可能重複:
Is there a reason why NullReferenceException does not give the name of the variable?C#編譯器相關的對象引用不設置到對象的實例
爲什麼還要更高層次的語言,如C#或Java想不出容易提供一種機制來發現哪個對象類型和實例(變量)爲空?我們是否需要爲此編寫自定義邏輯。
ex: SampleClass sc = null;
sc.SomeMethod();
我想說「對象類型的SC SampleClass爲空」,而不是一個天真的異常消息「對象引用不設置到對象的實例。」
可能的重複[是否有一個原因,爲什麼NullReferenceException不給變量的名稱?](http://stackoverflow.com/questions/5257626/is-there-a-reason-why-nullreferenceexception-does- not-the-name-of-the-varia),還有[爲什麼NullReferenceException不包含有關什麼是null的信息?](http://stackoverflow.com/questions/4719047/why-doesnt-nullreferenceexception-contain - 信息 - 關於 - 什麼 - 是空的) – Rawling