2011-03-26 82 views
-1

一个函数的测试,请参阅下面的代码:关于产品NullExceptionError在C#

List<Square> tempArr = new List<Square>(); 
Coin tempCoin = new Coin(eCoinType.White); 
Square tempMove = new Square(1, eColumn.A, tempCoin); 
tempArr.Add(tempMove); 
m_OtheloGame.isLegalMove(tempMove, ref tempArr); 

与NullExceptionError最后一行画“tempArr”的编译器。

我不明白为什么,因为我已经在第一行中分配了tempArr,所以它不能为空。

+2

你能解释一下你的意思是“编译器绘制tempArr”吗? – ChrisWue 2011-03-26 09:53:03

+0

是的我的意思是它用红色加下划线 – Mulder 2011-03-26 09:56:32

+0

当你试图编译它时,输出是什么? – ChrisWue 2011-03-26 09:58:14

回答

0

什么isLegalMove()方法做,因为tempArr中传递过来的裁判有可能,它可能被更改为引用空

0

外观为isLegalMove方法中的烦恼。 此外,请转到调试/例外并在两列上启用公共语言运行时例外:引发和用户未处理。然后再次运行,应在isLegalMove方法内通知您发生实际错误的位置。