Is there any difference between the 2 methods below for calculating c … specifically boxing/unboxing issues?
Dim a As Integer? = 10
Dim b As Integer? = Nothing
Dim c As Integer
' Method 1
c = If(a, 0) + If(b, 0)
' Method 2
c = a.GetValueOrDefault(0) + b.GetValueOrDefault(0)
According to Reflector, the IL from your code snippet decompiles into:
[EDIT] And then looking at the Reflected functions
GetValueOrDefault()andGetValueOrDefault(T defaultValue)gives the following (respectively):and
Indicating either form does effectively exactly the same thing