[英]How to create single dimensional, two dimensional,three dimensional as well as multi dimensional array using C#?
[英]How to assign a single column of a multi dimensional array to a single dimensional one?
我正在嘗試在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];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.