数组元如何相加啊?

paul9137 2009-01-24 01:33:52
Byte[]是int类型的数组。可是
Byte[2] = Byte[0] + Byte[1]无法直接相加,需要什么样的转换呢?
...全文
121 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
wuyq11 2009-01-24
  • 打赏
  • 举报
回复
或先转化为string,再转为int
Encoding myEncoding = Encoding.GetEncoding("utf-8");
byte[] mB = new byte[]{};
string str = myEncoding.GetString(byte[] mB)
http://www.cnblogs.com/ly4cn/archive/2005/09/08/232523.html
Crazy_Xia 2009-01-24
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 zgke 的回复:]
如果是byte需要转换
Byte[2] = (byte)(Byte[0] + Byte[1])
[/Quote]
-----------------------


需要注意可能会溢出
heatol 2009-01-24
  • 打赏
  • 举报
回复
Byte 换个名
paul9137 2009-01-24
  • 打赏
  • 举报
回复
错误 1 无法将类型“int”隐式转换为“byte”。存在一个显式转换(是否缺少强制转换?)
flyingdream123 2009-01-24
  • 打赏
  • 举报
回复
Byte[2] = Convert.ToInt32(Byte[0]) + Convert.ToInt32(Byte[1]);
landiao00o 2009-01-24
  • 打赏
  • 举报
回复
怎么会无法直接相加?有报什么错吗
zgke 2009-01-24
  • 打赏
  • 举报
回复
如果是byte需要转换
Byte[2] = (byte)(Byte[0] + Byte[1])

111,131

社区成员

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

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

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