我剛剛與我的一位同事討論了檢查空值的問題。關於檢查空值的問題
他發誓說:「在某些情況下,」下面的代碼想給他一個空值異常:
string test = null;
if(test == null) //error here
{
}
但如果代碼更改爲這不會有什麼錯誤:
string test = null;
if(null == test) //NO error here
{
}
我告訴過他這種事情沒有辦法發生,但他發誓固定他的代碼。有沒有可能出現上述變化可以解決錯誤的情況?
尋呼Eric Lippert ... – 2010-08-05 18:39:08
相關http://stackoverflow.com/questions/1264781/ – 2010-08-05 18:40:09
平等,這是不可交換?害怕。 – Marc 2010-08-05 18:41:01