To check if a value type is nullable I’m currently doing something like this:
int? i = null;
bool isNullable = i.GetType().ToString().Contains("System.Nullable");
Is there a more elegant way to do this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
You can use
Nullable.GetUnderlyingType(Type)– that will returnnullif it’s not a nullable type to start with, or the underlying value type otherwise:Note that this uses the
Nullablestatic class, rather than theNullable<T>structure.