1
我想了解爲什麼兩個代碼示例的行爲不同。我一直相信If()函數模仿If語言功能。或者我正在查看導致此問題的Nullable(Of Integer)的行爲?If()函數中可以爲空的整數的默認值
樣品#1:
If Not String.IsNullOrWhiteSpace(PC.SelectedValue) Then
Dim pcFilter1 As Integer? = CInt(PC.SelectedValue)
Else
Dim pcFilter1 As Integer? = Nothing
End If
樣品#2:
Dim pcFilter2 As Integer? = If(Not String.IsNullOrWhiteSpace(PC.SelectedValue),
CInt(PC.SelectedValue),
Nothing)
結果:
pcFilter1 =無
pcFilter2 = 0
很好的解釋。謝謝! – motto 2010-12-10 19:38:44