我试图从二维数组的第一列创建一个一维数组,在c#中。但是这段代码似乎不起作用
string[,] twoDArray;
//Some values are added to the array here
string[] oneDArray = twoDArray[,1];
我该怎么做?
你必须创建一个新的数组并在循环中填充它
string[,] twoDArray = new [,] {{"1","2"}, {"3","4"}, {"5","6"}};
int len = twoDArray.GetLength(0);
string[] oneDArray = new string[len];
for(int r=0;r<len; r++)
oneDArray[r] = twoDArray[r,1];