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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:14:52+00:00 2026-05-22T01:14:52+00:00

Is there anyway to know this? I found one post that asked a very

  • 0

Is there anyway to know this?

I found one post that asked a very similar question at How to check if an object is nullable? The answer explains how to determine if an object is nullable if there is access to a Generic Type Parameter. This is accomplished by using Nullabe.GetUnderlyingType(typeof(T)). However, if you only have an object and it is not null, can you determine if it is actually a Nullable ValueType?

In other words, is there a better way than checking every possible nullable value type individually to determine if a boxed struct is a value type?

void Main(){
    Console.WriteLine(Code.IsNullableStruct(Code.BoxedNullable));
} 


public static class Code{
    private static readonly int? _nullableInteger = 43;

    public static bool IsNullableStruct(object obj){
                  if(obj == null) throw new ArgumentNullException("obj");
                  if(!obj.GetType().IsValueType) return false;
                  return IsNullablePrimitive(obj);
            }
    public static bool IsNullablePrimitive(object obj){
         return obj is byte? || obj is sbyte? || obj is short? || obj is ushort? || obj is int? || obj is uint? || obj is long? || obj is ulong? || obj is float? || obj is double? || obj is char? || obj is decimal? || obj is bool? || obj is DateTime? || obj is TimeSpan?;
    }

    public static object BoxedNullable{
        get{ return _nullableInteger; }
    }
}

–

Update

I found this article at MSDN, and it says you can’t determine if a type is a Nullable struct via a call to GetType().

–

Update #2

Apparently the method I suggested doesn’t work either because int x = 4; Console.WriteLine(x is int?); is True. (See the comment)

  • 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-22T01:14:53+00:00Added an answer on May 22, 2026 at 1:14 am

    Quoting Jon Skeet’s comment in the question you linked:

    there’s no such thing as a boxed nullable type – Nullable gets boxed to a null reference or a boxed int

    so in your example program by the time BoxedNullable is passed to IsNullableStruct which takes an object as a parameter, the value is already a boxed 43, no longer a nullable anything. Ironically x is int? is true for any int, nullable or otherwise, so that only adds to the confusion.

    In any case, your original question, according to Jon’s comment, doesn’t seem to make sense.

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

Sidebar

Related Questions

I know this is a long shot - but is there any way at
Is there anyway in Java to delete data (e.g., a variable value, object) and
I know this is a probable open ended question, and I have tried looking
Is there any way to know if I'm compiling under a specific Microsoft Visual
I have two keyboards connected to my PC, is there any way to know
I know you can do it file by file. Is there any way to
I would like to know if there is any way to add custom behaviour
and I would like to know if there is any way to stop a
Is there anyway to have a sort of virtual static member in C++? For
Is there anyway to configure a WCF service with a failover endpoint if the

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.