我试图在我的类中覆盖 Equals,但我得到了这个我不明白的错误“对象引用未设置为对象的实例”
我的代码:
public override bool Equals(object obj)
{
return this.Equals((Chapter)obj);
}
public bool Equals(Chapter other)
{
return this.KeyFromChapterName == other.KeyFromChapterName &&
this.Name == other.Name;
}
我究竟做错了什么 ?
编辑 1(堆栈跟踪):
Object reference not set to an instance of an object.
at Wurth.TarifImageOdsFormatter.Process.Items.Chapter.Equals(Chapter other) in C:\Projet\KeyAccountExporter\Wurth.KeyAccountExporter\Wurth.TarifImageOdsFormatter.Process\Items\Chapter.cs:line 32
at Wurth.TarifImageOdsFormatter.Process.ProgramV2.Main(String[] args) in C:\Projet\KeyAccountExporter\Wurth.KeyAccountExporter\Wurth.TarifImageOdsFormatter.Process\ProgramV2.cs:line 110
第 110 行是if(myChapter.Equals(OtherChapter)
,第 32 行是我开始的地方:
public bool Equals(Chapter other)
{
return this.KeyFromChapterName == other.KeyFromChapterName &&
this.Name == other.Name;
}