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

  • Home
  • SEARCH
  • 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 169507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T12:38:35+00:00 2026-05-11T12:38:35+00:00

I was wondering if anyone knows how the C# compiler handles the following assignment:

  • 0

I was wondering if anyone knows how the C# compiler handles the following assignment:

int? myInt = null; 

My assumption is that there is an implicit conversion performed, but I cannot figure out how the null literal assignment is handled. I dissasembled the System.Nullable object and found the implicit operator is overriden to this:

public static implicit operator T?(T value)  {     return new T?(value);   } 

Once called this would try to fire the secondary constructor:

public Nullable(T value) {     this.value = value;     this.hasValue = true;  } 

Which is where my confusion comes into play… this.value is of some value type and cannot be null.

So, does anyone know how this ‘magic’ takes place… or am I wrong in assuming that the secondary constructor is called? Does the default constructor get called because the compiler knows that it cannot match the second contructor’s signature with the null literal (resulting in myInt being assigned to a new ‘null’ Nullable)?

  • 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. 2026-05-11T12:38:35+00:00Added an answer on May 11, 2026 at 12:38 pm

    The statement:

    int? myInt = null; 

    Gets compiled as:

      .locals init (valuetype [mscorlib]System.Nullable`1<int32> V_0)   IL_0000:  ldloca.s   V_0   IL_0002:  initobj    valuetype [mscorlib]System.Nullable`1<int32> 

    Which, according to the MSDN, means «Initialize each field of the value type at a specified address to a null reference or a 0 of the appropriate primitive type.»

    So there’s no constructor or conversion here. HasValue will return false, and trying to get its Value will throw an InvalidOperationException. Unless you use GetValueOrDefault of course.

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

Sidebar

Related Questions

I'm wondering if anyone knows of a PHP library that I could compile into
I was wondering whether anyone knows of any tools available that perform the task
I was wondering if anyone knows of any large sites that use progressive enhancement/CSS3?
I was wondering if anyone knows if there is an option in the eBay
I'm wondering if anyone knows of a PHP setting that will automatically escape double
I was wondering if anyone knows how to use a new compiler within visual
Just wondering whether anyone knows how to get blogger labels into alt tags in
I was wondering whether anyone knows definitively if LINQ to SQL has the capability
I was wondering if anyone knows more about the inner workings of the Google
Hi i was wondering if anyone knows how i can calculate the difference between

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.