【发布时间】:2019-02-10 10:21:45
【问题描述】:
我有一个string[,] 和一定数量的string[],它们保持不变,我想从中挑选一些并将它们放在list<string[]> 中(我使用一个列表使其可扩展)。但是list<string[]> 不会接受来自string[,] 的任何string[]。
string[,] testArray =
{
{"testValue1", "testValue1.1"}
{"testValue2", "testValue2.1"}
{"testValue3", "testValue3.1"}
}
List<string[]> testList = new List<string[]>();
testList.Add(testArray[1]) //error: wrong number of indicaters inside[]
testList.Add(testArray[1,1]) //error: cannot convert from string to string[]
【问题讨论】:
-
testList.Add(new [] {testArray[1,1]})等等... -
string[,] 不是数组数组,它是二维数组。也许你想要字符串[][]?那里的 testArray 是宽度为 2 和高度为 3 的字符串矩阵,并且没有简单的方法来迭代单行/列,您必须为此执行自己的 for 循环。 (或者可能是扩展方法)
-
“字符串列表”是
List<string>,而不是List<string[]>