byte[]处理 我有byte[]类型的数组,求函数 去掉byte[]数组的前六个和后四个 谢谢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 Array.Copybyte[] _Temp =........ byte[] _ValueBytes = new byte[_Temp.Length - 10]; Array.Copy(_Temp, 6, _ValueBytes,0, _ValueBytes.Length); 但是怎么处理byte[] _ValueBytes = new byte[_Temp.Length - 10]; 中的Temp.Length -10 异常? byte[] abyt = new byte[13] { 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd };foreach (byte a in abyt) Console.Write("{0} ", a);byte[] bbyt = new byte[abyt.Length - 10]; Console.WriteLine(" ");Array.Copy(abyt, 6, bbyt, 0, abyt.Length - 10);foreach (byte b in bbyt) Console.Write("{0} ", b);Console.WriteLine("按任意键退出");Console.ReadLine(); byte[] _ValueBytes //你自己的if(_ValueBytes.Length<=10) throw new Exception("不够长");byte[] by= new byte[_ValueBytes.Length-10]for(int i =0;i<by.Length;i++){ by[i]= _ValueBytes[i+3];} 但是运行的时候 throw new Exception("不够长"); 说是未处理的异常,怎么回事啊 如果想处理异常,还可以在调用处 try catch 处理 public byte[] Del_Head(byte[] b,int len) { if (len > 6) { byte[] bb = new byte[len - 6]; Array.Copy(b, 6, bb, 0, bb.Length); return bb; } else throw new Exception("不够长"); }***************就是这段代码,也能够运行,但运行到最后会定位到“throw new Exception("不够长"); ” 说未处理换成try catch 处理也不能够通过 public void limite(byte[] byt) { byte[] byt2 = new byte[byt.Length - 10]; for (int i = 6; i <= byt.Length - 4; i++) { byt2[i - 6] = byt[i]; } } 先try再throw new Exception("不够长"); 那是因为你原来的数组_ValueBytes的长度不够..你想一下..前面剪了4位,后面又剪6位,,这样的话你的_ValueBytes至少应该有10位..假如不够10位,肯定会出错 弱弱地问个C#借口的问题。。 提示信息页面如何制作 .net中 可不可以跟踪类里面的函数调用过程? 数据库标识符问题 高手帮忙啊 xmlspy2010中自动生成c#代码如何使用,谁能给一个完整的例子 初学ADO,分不多请包涵! C# 两个Label控件图片并列边框重叠问题 C# asp.net web 程序中有两个 aspx页面,B页面如何调用A页面中的控件? 为什么新开启的线程代码不执行呢? 新手提问 怎么用c#创建空的word文档
byte[] _ValueBytes = new byte[_Temp.Length - 10];
Array.Copy(_Temp, 6, _ValueBytes,0, _ValueBytes.Length);
byte[] _ValueBytes = new byte[_Temp.Length - 10];
中的Temp.Length -10 异常?
byte[] abyt = new byte[13] { 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd };
foreach (byte a in abyt)
Console.Write("{0} ", a);
byte[] bbyt = new byte[abyt.Length - 10];
Console.WriteLine(" ");
Array.Copy(abyt, 6, bbyt, 0, abyt.Length - 10);
foreach (byte b in bbyt)
Console.Write("{0} ", b);
Console.WriteLine("按任意键退出");
Console.ReadLine();
if(_ValueBytes.Length<=10)
throw new Exception("不够长");byte[] by= new byte[_ValueBytes.Length-10]for(int i =0;i<by.Length;i++)
{
by[i]= _ValueBytes[i+3];
}
throw new Exception("不够长");
说是未处理的异常,怎么回事啊
如果想处理异常,还可以在调用处 try catch 处理
{ if (len > 6)
{
byte[] bb = new byte[len - 6]; Array.Copy(b, 6, bb, 0, bb.Length); return bb;
}
else
throw new Exception("不够长");
}
***************
就是这段代码,也能够运行,但运行到最后会定位到“throw new Exception("不够长"); ” 说未处理
换成try catch 处理也不能够通过
public void limite(byte[] byt)
{ byte[] byt2 = new byte[byt.Length - 10]; for (int i = 6; i <= byt.Length - 4; i++)
{
byt2[i - 6] = byt[i];
}
}
那是因为你原来的数组_ValueBytes的长度不够..你想一下..前面剪了4位,后面又剪6位,,这样的话你的_ValueBytes至少应该有10位..假如不够10位,肯定会出错