#542 – Conventions for Naming Type Parameters
March 19, 2012 Leave a comment
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) {