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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:16:44+00:00 2026-05-22T02:16:44+00:00

Surprisingly the following code fails the Assert: int? wtf = 0; Assert.IsType<Nullable<int>>(wtf); So just

  • 0

Surprisingly the following code fails the Assert:

int? wtf = 0;
Assert.IsType<Nullable<int>>(wtf);

So just out curiosity, how can you determine if a given instance is a Nullable<> object or not?

  • 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-22T02:16:45+00:00Added an answer on May 22, 2026 at 2:16 am

    Well firstly, Nullable<T> is a struct, so there isn’t an object as such. You can’t call GetType(), as that will box the value (at which point you either get null and thus an exception, or a boxed non-nullable value and therefore not the type you want).

    (Boxing is what’s messing up your assertion here – I would assume that IsType accepts object.)

    You can use type inference though to get the type of the variable as a type parameter:

    public bool IsNullable<T>(T value)
    {
        return Nullable.GetUnderlyingType(typeof(T)) != null;
    }
    

    That’s not a huge amount of use when you know the exact type at compile-time as in your example, but it’s useful for generics. (There are alternative ways of implementing it, of course.)

    What’s your real life situation? I assume it’s not an assertion like this, given that you know the answer to this one at compile time.

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

Sidebar

Related Questions

Surprisingly as you get good at vim, you can code even faster than standard
I'm sure there are a million posts about this out there, but surprisingly I'm
Have a look at the following piece of code Header File: class CxUser {
Consider the following code: class Program { void Foo<T>() { } static void Main(string[]
I am trying to send an email using c# using the following code. MailMessage
i am experiencing some weird behaviour here. i am using the following code to
I have looked everywhere and surprisingly can't find a good solution to this! I've
I was testing the access to the Internic WHOIS with the following code: $domains
Consider the two following Python code examples, which achieves the same but with significant
Surprisingly I was only able to find one previous question on SO about this

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.