Cook Computing

Generic Argument of Nullable Type

November 1, 2005 Written by Charles Cook

For future reference, sample code on how to get the generic argument of a nullable type in C#:


Type type = typeof(int?);

bool isNullable = type.IsGenericType
  && (type.GetGenericTypeDefinition() == typeof(Nullable<>));

Type genArg = type.GetGenericArguments()[0];