var a = b?.c.d; 這個表達式不應該總是給出編譯錯誤嗎?如果b爲null,則通過傳播null值,所以c也將爲null,因此也需要此運算符。根據我的理解,在表達式中使用此運算符會傳播病毒。 但是,Visual Studio 2015和Resharper都沒有對我說什麼,我在這裏錯過了什麼嗎?
如果變量值爲Nothing,我們遇到了空條件運算符的意外行爲。 下面的代碼的行爲讓我們有點糊塗 Dim l As List(Of Object) = MethodThatReturnsNothingInSomeCases()
If Not l?.Any() Then
'do something
End If
預期的行爲是Not l?.Any()是truthy如果l
在執行成員訪問之前,我已經知道空條件運算符can be used to test爲null。 例如: int? length = customers?.Length; // null if customers is null
Customer first = customers?[0];
如果customers在customers?.Length爲null,則customers?.Lengt