我有byte[]类型的数组,求函数 去掉byte[]数组的前六个和后四个 谢谢

解决方案 »

  1.   

    Array.Copybyte[] _Temp =........
                byte[] _ValueBytes = new byte[_Temp.Length - 10];
                Array.Copy(_Temp, 6, _ValueBytes,0, _ValueBytes.Length);
      

  2.   

    但是怎么处理
    byte[] _ValueBytes = new byte[_Temp.Length - 10]; 
    中的Temp.Length -10 异常?
      

  3.   


    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();
      

  4.   

    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];
    }
      

  5.   

    但是运行的时候
      throw new Exception("不够长"); 
    说是未处理的异常,怎么回事啊
      

  6.   


    如果想处理异常,还可以在调用处 try  catch 处理
      

  7.   

    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 处理也不能够通过
      

  8.   


     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];
                }
            
            }
      

  9.   

    先try再throw new Exception("不够长"); 
      

  10.   


    那是因为你原来的数组_ValueBytes的长度不够..你想一下..前面剪了4位,后面又剪6位,,这样的话你的_ValueBytes至少应该有10位..假如不够10位,肯定会出错