0
可以说我有一个这样的数组:1索引与二维数组错误
byte[,] arr = new byte[4,4];
byte[] x = arr[0]; // error here
怎么来的,我不能做到这一点,错误即时得到:
Indexer has 2 parameters but is invoked with 1 argument
感谢 丹尼尔
可以说我有一个这样的数组:1索引与二维数组错误
byte[,] arr = new byte[4,4];
byte[] x = arr[0]; // error here
怎么来的,我不能做到这一点,错误即时得到:
Indexer has 2 parameters but is invoked with 1 argument
感谢 丹尼尔
你的arr
数组是一个二维数组,所以想象一个网格。因此,您需要两个索引才能访问任何元素:行索引和列索引。
如果你想获得整行,这看起来像你正在尝试做的那样,那么你将需要使用交错数组,如pm100所说的用户。
// Initialize array size
byte[][] arr = new byte[4][];
for (int i = 0; i < arr.GetLength(0); i++)
arr[i] = new byte[4];
// Grab the first row
byte[] x = arr[0];
你需要锯齿状的数组https://msdn.microsoft.com/en-us/library/2s05feca.aspx – pm100 2015-02-06 01:49:43
什么是不明确的错误?你有一个2d数组,如果你想索引一个元素,你需要指定两个参数。 – 2015-02-06 01:50:06
请参阅http://stackoverflow.com/questions/597720/what-are-the-differences-between-a-multidimensional-array-and-an-array-of-array – artm 2015-02-06 01:53:49