Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 667697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:57:25+00:00 2026-05-13T23:57:25+00:00

Is there any difference between the 2 methods below for calculating c … specifically

  • 0

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)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T23:57:26+00:00Added an answer on May 13, 2026 at 11:57 pm

    According to Reflector, the IL from your code snippet decompiles into:

    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
    

    [EDIT] And then looking at the Reflected functions GetValueOrDefault() and GetValueOrDefault(T defaultValue) gives the following (respectively):

    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
    

    Indicating either form does effectively exactly the same thing

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any difference between the below 2 CREATE TABLE statements in SQL Server
Is there any semantic difference between ToXXXX conversion methods and AsXXXX conversion methods in
Possible Duplicate: Differences in string compare methods in C# Is there any difference between
Is there any difference between .create() and .show() methods of AlertDialog's builder class? Like
Is there any dramatic difference between functions and methods in Objective -C?
Is there any difference between these methods of declaring and setting a public class
Is there any difference between these two methods of moving a file? System.IO.FileInfo f
Is there any difference between the Java PrintWriter methods printf and format ? The
Is there any difference in between the two method definitions below? Eclipse does not
Is there any difference between ReferencePath with condition '%(CopyLocal)'=='true' and ReferenceCopyLocalPaths ? The question

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.