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 542047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:24:22+00:00 2026-05-13T10:24:22+00:00

Have you ever tried to use the Convert.ChangeType() method to convert a value to

  • 0

Have you ever tried to use the Convert.ChangeType() method to convert a value to a Nullable<T> type? Awkwardly, it will throw an InvalidCastException saying “Null object cannot be converted to a value type”.

Try running this on your immediate window: ?System.Convert.ChangeType(null, typeof(int?))

For some obscure reason, Nullables are considered value types. For example, typeof(int?).IsValueType returns true.

For me, since Nullable<T> accept null, it’s a class type, not a value type. Does anyone know why it would implemented differently?

  • 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-13T10:24:22+00:00Added an answer on May 13, 2026 at 10:24 am

    System.Nullable<T> is technically a structure, so it’s a value type (the null value for a Nullable<T> is not exactly the same thing as a null reference. It’s a boolean flag that denotes the lack of a value.) However, it’s treated specially by the runtime and this makes it an awkward value type. First, it doesn’t satisfy where T : struct type constraint (it doesn’t satisfy where T : class either, for what it’s worth). Second, it exhibits an interesting boxing behavior. Boxing a Nullable<T> will result in:

    • A null reference, if the value is null.
    • A boxed value of the underlying type if it actually contains a value. That is, in the statements:

      int? x = 2;
      object y = x;
      

      y is not a boxed Nullable<int>. It’s simply a boxed int. You can unbox any boxed value of type T to Nullable<T> (and T, of course). Casting a null reference to Nullable<T> results in a null value (as you might expect).

    This special treatment by the runtime makes nullable types work more similar to the way null works in reference types.

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

Sidebar

Related Questions

Have you ever tried learning a language while on a project? I have, and
Have anybody ever tried to create thumbnails/previews of MS Office files? I do not
have You ever tried to import classic c++/make project into QtCreator ? Lets say
With all of the programming I have ever done in my entire life I
For those of you who have ever used Microsoft Excel in a manner that
Have you ever done any .net programming? Yes? Good, here's a massive broken program,
Have you ever obfuscated your code before? Are there ever legitimate reasons to do
Have you ever created or encountered a self modifying code in Java? If yes,
Have you ever had to justify the choice over using .NET instead of Java
Have you ever added unit tests, after the fact, to legacy code? How complicated

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.