-2
时,我有下面的C#代码:初始化的ArrayIndexOutOfBounds名单<int[,]>
List<int[,]> l1 = new List<int[,]>();
l1[0] = new int[1, 1];
它将引发System.ArgumentOutOfRangeException在脸上的权利。
怎么回事?
时,我有下面的C#代码:初始化的ArrayIndexOutOfBounds名单<int[,]>
List<int[,]> l1 = new List<int[,]>();
l1[0] = new int[1, 1];
它将引发System.ArgumentOutOfRangeException在脸上的权利。
怎么回事?
列表默认创建空的,与Add()
List<int[,]> l1 = new List<int[,]>();
l1.Add(new int[1, 1]);
更换[]
或使用.NET 4.0初始化(语义相同以上):
List<int[,]> l1 = new List<int[,]>(){new int[1, 1]};
您需要使用List.Add名录和l1.Add(new int[1, 1]);
不是索引访问