我试图让列表的一维数组。我做这样的:数组列表中抛出的NullReferenceException
public static List<string>[] words = new List<string>[30];
public static List<string>[] hints = new List<string>[30];
我这样称呼它:
foreach (string item in vars.directory)
{
reader2 = new StreamReader(item);
while (reader2.Peek() > 0)
{
string line = reader2.ReadLine();
if (line.StartsWith("#"))
{
vars.words[counter].Add(line.Substring(1, line.Length - 1)); //here
}
else if (line.StartsWith("-"))
{
vars.hints[counter].Add(line.Substring(1, line.Length - 1)); //another here
}
else if (line == "@end")
{
counter++;
}
}
}
我只是想补充一点,瓦尔在这里我把我的公共变量和计数器的确是在0时循环开始。
编辑 在我匆忙我忘了补充问题......哎呀......
这就是:当我调用add函数(或任何与此有关的另一个功能),它返回一个空引用异常。我怎样才能解决这个问题?
问题是什么? – 2011-03-15 19:56:04
对不起...当我调用add函数时,它返回一个空引用异常。 – 2011-03-15 19:58:15
见http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-in-net – 2011-03-15 20:27:59