将一个short数组转怎么byte数组

jyqxj 2010-05-17 04:50:12
将一个short数组转怎么byte数组
...全文
165 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
abeniaj0427 2010-05-17
  • 打赏
  • 举报
回复
 public void Test() {
short[] st = new short[] { 0x01, 0x03, 0x02, 0x04 };

byte[] b= Array.ConvertAll(st, new Converter<short, byte>(ShortToByte));
foreach (byte n in b)
{
this.d.Text += n + ":";
}
}
public static byte ShortToByte(short pf)
{
return Convert.ToByte(pf);
}
jyqxj 2010-05-17
  • 打赏
  • 举报
回复
自己弄错哦了
jyqxj 2010-05-17
  • 打赏
  • 举报
回复
提示有错
不知道错在哪里
cjcgy 2010-05-17
  • 打赏
  • 举报
回复
不考虑溢出的话:


short[] shortArray = new short[] { 0x00, 0x05 };

byte[] byteArray = Array.ConvertAll<short, byte>(shortArray, new Converter<short, byte>(delegate(short value)
{
return (byte)value;
}));

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧