#542 – Conventions for Naming Type Parameters

You can name type parameters in generic classes and generic methods anything you like.  But you should typically follow the following naming conventions for naming type parameters:

  • Use a short descriptive name
  • Use “T” as the first letter of the type parameter
  • Use “T” alone as the type parameter if it is the only parameter and if a longer name would not make its use more clear

Here are a couple examples from the .NET Framework source code:

    class ReadOnlyDictionary<TKey, TValue> : IDictionary<TKey, TValue>
        IDictionary<TKey, TValue> dictionary;

        public ReadOnlyDictionary(IDictionary<TKey, TValue> dictionary)
            : this(dictionary, true)


        public static ReadOnlyCollection<T> AsReadOnly<T>(T[] array) {

About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: