我正在尝试用C#中的二维数组的第一列创建一维数组。但是这段代码似乎不起作用
string[,] twoDArray;
//Some values are added to the array here
string[] oneDArray = twoDArray[,1];
我该怎么做?
答案 0 :(得分:2)
你必须创建一个新数组并将其填入循环
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];