J
Joe Bloggs
Hi,
Can someone please kindly show me how to determine if a type (read value
type) is Nullable.
MSDN has this KB:
How to: Identify a Nullable Type (C# Programming Guide)
http://msdn2.microsoft.com/en-us/library/ms366789.aspx
however, using their code snippet, I couldn't get it to work:
public class MyClass
{
public static void Main()
{
Nullable<int> j = new Nullable<int>(20);
Type type = j.GetType();
if (type.IsGenericType && type.GetGenericTypeDefinition() ==
typeof(Nullable<>))
{
Console.WriteLine("j is Nullable");
}
else
Console.WriteLine("j is NOT Nullable");
Console.WriteLine("Type of j is {0}", j.GetType());
}
}
The Output I got is:
j is NOT Nullable
Type of j is System.Int32
thus, is there no way to determine a nullable or an non-nullable value
types?
Thanks for your help in advanced.
Can someone please kindly show me how to determine if a type (read value
type) is Nullable.
MSDN has this KB:
How to: Identify a Nullable Type (C# Programming Guide)
http://msdn2.microsoft.com/en-us/library/ms366789.aspx
however, using their code snippet, I couldn't get it to work:
public class MyClass
{
public static void Main()
{
Nullable<int> j = new Nullable<int>(20);
Type type = j.GetType();
if (type.IsGenericType && type.GetGenericTypeDefinition() ==
typeof(Nullable<>))
{
Console.WriteLine("j is Nullable");
}
else
Console.WriteLine("j is NOT Nullable");
Console.WriteLine("Type of j is {0}", j.GetType());
}
}
The Output I got is:
j is NOT Nullable
Type of j is System.Int32
thus, is there no way to determine a nullable or an non-nullable value
types?
Thanks for your help in advanced.