1

When talking about a generic type, Foo<T>, T is called the generic argument or type argument of generic type Foo in the .NET System.Type documentation.

Now, when I am dealing with a type such as int? or Nullable<Bar>, how do I refer to the generic argument (i.e. int or Bar in my example) when describing the type?

I'd call it the base type of the nullable type, but base type is usually used to refer to the parent class, when describing a class hierarchy... so I don't feel it is right to be talking about a base type here. And using the terminology the generic argument of the nullable type makes me feel to general.

So how do you speak about these types?

And more specifically, how would you name this extension method:

public static System.Type GetXxxType(this System.Type type)
{
    if ((type.IsGenericType) &&
        (type.GetGenericTypeDefinition () == typeof (System.Nullable<>)))
    {
        return type.GetGenericArguments ()[0];
    }
    else
    {
        return null;
    }
}

When passed a Nullable<T> this method returns typeof(T) as a result.

Pierre Arnaud
  • 10,212
  • 11
  • 77
  • 108

1 Answers1

4

from the spec:

A nullable type can represent all values of its underlying type plus an additional null value. A nullable type is written T?, where T is the underlying type

Edit:

reference: C# 4 spec section 4.1.10 Nullable types

saus
  • 2,136
  • 17
  • 15