Getting a double[] row array of a double[,] rectangular array

后端 未结 6 1817
夕颜
夕颜 2021-02-13 13:43

Suppose you have an array like:

double[,] rectArray = new double[10,3];

Now you want the fouth row as a double[] array of 3 elements without do

6条回答
  •  梦毁少年i
    2021-02-13 14:28

    You can use Buffer.BlockCopy method:

    const int d1 = 10;
    const int d2 = 3;
    const int doubleSize = 8;
    
    double[,] rectArray = new double[d1, d2];
    double[] target = new double[d2];
    
    int rowToGet = 3;
    Buffer.BlockCopy(rectArray, doubleSize * d2 * rowToGet, target, 0, doubleSize * d2);
    

提交回复
热议问题