开发者

.NET: How do I tell if a type is nullable? [duplicate]

This question already has answers here: Closed 12 years ago.

Possible Duplicate:

How to check if an object is nullable?

I have a System.Type object which may be a Nullable&l开发者_StackOverflow中文版t;T>. How would I determine this at runtime?

Note: At this point I don't care what T is, I just need to know whether or not it is a Nullable.


Possible duplicate:

How to check if an object is nullable?

if not..

bool IsNullableType(Type theType)
{
    return (theType.IsGenericType && 
    theType.GetGenericTypeDefinition().Equals(typeof(Nullable<>)));
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜