Is there any difference between using .GetValueOrDefault(0) and If(variable, 0) with nullable types?

Posted by burlmd on Stack Overflow See other posts from Stack Overflow or by burlmd
Published on 2010-03-09T00:51:25Z Indexed on 2010/03/09 4:06 UTC
Read the original article Hit count: 273

Filed under:
|
|
|

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)

© Stack Overflow or respective owner

Related posts about vb.net

Related posts about nullable