據的反射器,從您的代碼段的IL反編譯成:
Public Shared Sub Main()
Dim a As Integer? = 10
Dim b As Integer? = Nothing
Dim c As Integer = (IIf(a.HasValue, a.GetValueOrDefault, 0) + IIf(b.HasValue, b.GetValueOrDefault, 0))
c = (a.GetValueOrDefault(0) + b.GetValueOrDefault(0))
End Sub
[編輯],然後着眼於反射功能GetValueOrDefault()
和GetValueOrDefault(T defaultValue)
給出以下(分別):
Public Function GetValueOrDefault() As T
Return Me.value
End Function
and
Public Function GetValueOrDefault(ByVal defaultValue As T) As T
If Not Me.HasValue Then
Return defaultValue
End If
Return Me.value
End Function
表示是形式確實有效完全一樣的東西
順便說一句,「VB.NET」是一個詞 – 2010-03-09 00:54:26