我試圖讓列表的一維數組。我做這樣的:數組列表中拋出的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