C# 关于C中NullExceptionError的问题#

C# 关于C中NullExceptionError的问题#,c#,nullreferenceexception,compiler-errors,C#,Nullreferenceexception,Compiler Errors,有关函数的测试,请参见以下代码: 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); Lis

有关函数的测试,请参见以下代码:

 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);
List tempArr=new List();
硬币tempCoin=新硬币(eCoinType.White);
Square tempMove=新Square(1,eColumn.A,tempCoin);
tempArr.Add(tempMove);
m_Otherogame.isLegalMove(tempMove,ref tempArr);
编译器在最后一行中使用NullExceptionError绘制了“tempArr”


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

isLegalMove()方法做什么,因为tempArr作为ref传入,所以它可能被更改为引用null

查找
isLegalMove
方法内部的问题。
另外,转到Debug/Exceptions并在两列上启用公共语言运行时异常:抛出和用户未处理。然后再次运行,您会收到通知,实际错误发生在
isLegalMove
方法中。

您能解释一下“编译器绘制的tempArr”是什么意思吗?是的,我的意思是它用红色下划线。您尝试编译它时的输出是什么?您能发布异常的详细信息吗?调用堆栈中的内容可能比我们在问题中看到的要多。您真的需要通过引用传递
tempArr