Reputation: 481
I am trying to create a one dimensional array from the first column of a two dimensional array, in C#. But this code does not seem to work
string[,] twoDArray;
//Some values are added to the array here
string[] oneDArray = twoDArray[,1];
How can I do it?
Upvotes: 0
Views: 239
Reputation: 35730
you have to create a new array and fill it in a loop
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];
Upvotes: 2