I am trying to understand why the two code samples behave differently. I always believed the If() function to mimic the If language feature. Or am I looking at a behavior of Nullable(Of Integer) that is causing this?
Sample #1:
If Not String.IsNullOrWhiteSpace(PC.SelectedValue) Then
Dim pcFilter1 As Integer? = CInt(PC.SelectedValue)
Else
Dim pcFilter1 As Integer? = Nothing
End If
Sample #2:
Dim pcFilter2 As Integer? = If(Not String.IsNullOrWhiteSpace(PC.SelectedValue),
CInt(PC.SelectedValue),
Nothing)
Result:
pcFilter1 = Nothing
pcFilter2 = 0