数组1
byte[] byte1 = {1,2,3,4,5,6};
数组2
byte[] byte2;
如何将byte2指向数组1的一个子数组,如{2,3,4,5, 6}或者{3,4,5,6};
就像C++中的指针赋值:
byte2 = &byte1[3];

解决方案 »

  1.   

    byte[] byte1 = new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 };
    byte[] byte2 = byte1.Skip(3).ToArray();
      

  2.   

    Array.Copy(Array sourceArray, int sourceIndex, Array destinationArray, int destinationIndex, int length)
    具体用法看MSDN
      

  3.   

    首先要做项目属性中启用不安全代码            unsafe
                {
                    fixed (byte* a = new byte[] { 1, 2, 3, 4, 5 })
                    {
                        byte* b = a+2;//b从3 开始
                    }
                }
      

  4.   

    可以用dictionary的key来试试,仅仅是个思路Dictionary<List<int>, List<byte>> dicbyte = new Dictionary<List<int>, List<byte>>();
                // 前面是个整数数组,表示 List<byte>值的索引,根据索引来指定List<byte>的子数组
                List<byte> list = new List<byte> { 1, 2, 3, 4, 5, 6 };
                List<int> list1 = new List<int> { 1, 2, 3, 4, 5 };
                List<int> list2 = new List<int> { 2, 3, 4, 5 };
      

  5.   

    class SubArray<T>
    {
        private T[] _refarray;
        private int startpos;
        publc SubArray(T[] source, int startpos)
        {
            _refarray = source; _startpos = startpos;
        }    public this[int index]
        {
            get { return _refarray[startpos + index]; }
            set { _refarray[startpos + index] = value; }
        }
    }
      

  6.   

    byte[] byte1 = new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 };
    SubArray<byte> byte2 = new SubArray<byte>(byte1, 3);
    byte2[1] = 0x08;
      

  7.   


    大哥, 你这种unsafe的代码我看可行, 就跟c++一样, 但如果我分装成一个dll, 提供接口给别人用, 人家会发现这个是unsafe的么? 他们的工程属性也要修改么?