这里有什么问题吗?
string[] keysDictionary = new string[]{};
keysDictionary [0] = "test";
我明白了
System.IndexOutOfRangeException Array index is out of range.
最佳答案
您不能向长度为 0 的数组添加任何内容。您实际上是在尝试设置没有元素的数组的第一个元素的值。如果您想这样做,请改用列表之类的东西,数组不能调整大小。
var keysDictionary = new List<string>();
keysDictionary.Add("test");
关于c# - 创建空数组并添加值导致 "Array index is out of range",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25806361/