我正在尝试做问题所说的。 (可能令人困惑) 这里有一些代码可以让你理解我正在尝试做的事情。
classes = new string[14, 5];
classes[0] = {"Value1 [0, 0]", "Value2 [0, 1]", "Value3 [0, 2]", "Value4 [0, 3]", "Value5 [0, 4]"};
答案 0 :(得分:1)
某些语言或环境(如Matlab)允许这样的操作,但C#不能为矩形数组String [x,y]提供此类访问。
使用此类数组,您应该单独更改每个元素:
String[,] classes = new string[14, 5];classes = new string[14, 5];
Int32 rowToChange = 0;
for(Int32 col = 0; col < classes.GetLength(1); col++)
{
classes[rowToChange, col] = String.Format("Value{0} [{1}. {0}]", rowToChange , col );
}
但你可以使用锯齿状数组:String [] []
String[][] classes = new string[14][];
Int32 rowToChange = 0;
classes[rowToChange] = new String[]{"Value1 [0, 0]", "Value2 [0, 1]", "Value3 [0, 2]", "Value4 [0, 3]", "Value5 [0, 4]"};
您可以阅读What are the differences between a multidimensional array and an array of arrays in C#?以了解差异