How to copy a row of values from a 2D array into a 1D array?

前端 未结 6 2151
醉话见心
醉话见心 2020-12-05 08:17

We have the following object

int [,] oGridCells;

which is only used with a fixed first index

int iIndex = 5;
for (int iLoop         


        
6条回答
  •  再見小時候
    2020-12-05 08:39

    You can try this:

     int[,] twoD = new int[2,2];
     twoD[0, 0] = 1;
     twoD[0, 1] = 2;
     twoD[1, 0] = 3;
     twoD[1, 1] = 4;
    
     int[] result = twoD.Cast().Select(c => c).ToArray();
    

    The result will be an integer array with data:

    1, 2, 3, 4
    

提交回复
热议问题