tags:

views:

321

answers:

3

Why does

properties[5].PropertyType.GetGenericTypeDefinition() == 
   Type.GetType("System.Nullable`1")

equals to true while

properties[5].PropertyType.GetGenericTypeDefinition() ==
   Type.GetType("System.Nullable")

equals to false?

Properties[5] being a public Nullable<DateTime> field.

What does the `1 after the System.Nullable mean?

+4  A: 

The `1 means that the type is a generic type. Since it's possible to have a type called "Foo" as well as a type called "Foo" then there needs to be some internal way for the two types to be differentiated.

Since there's a non-generic System.Nullable type but you're using a generic type, your comparison to GetType("System.Nullable") will always return false.

Matt Hamilton
+3  A: 

Nullable`1 is the real name of the class you know of as Nullable<T> in C# (Or Nullable(Of T) in VB.Net).

Nullable is a static class with a number of helper methods for using Nullable<T>.

Jonathan
A: 

For more details on nullable type please see Nullanle type

bimbim.in