Skip to main content
adjusted answer considering comments.
Source Link
Matthieu
  • 4.6k
  • 2
  • 37
  • 38

Microsoft has an official guideline regarding generics : Names of Classes, Structs, and Interfaces (quoted here, and in book form : Framework Design Guidelines ).

Regarding your specific question it says :

I recommend using a single capital letter for aDo name generic type parameters with descriptive names, unless a parameter. If you have no additional contextual information about thesingle-letter name is completely self explanatory and a descriptive type parameter, you should use the letter T:name would not add value.

publicIDictionary<TKey, classTValue> MyClass<T>
{...}

In all other cases,is an example of an interface that follows this guideline.

Consider using the official Microsoft guidelinesletter T as the type parameter name for generictypes with naming conventions are:one single-letter type parameter.

  • Name generic type parameters with descriptive names, unless a single letter name is completely self explanatory and a descriptive name would not add value.
public interface ISessionChannel<TSession> 
{...}
public delegate TOutput Converter<TInput,TOutput>(TInput from);

Do prefix descriptive type parameter names with the letter T.

  • Consider indicating constraints placed on a type parameter in the name of parameter. For example, a parameter constrained to ISession may be called TSession.

Consider indicating constraints placed on a type parameter in the name of parameter. For example, a parameter constrained to ISession may be called TSession.

Microsoft has an official guideline regarding generics here.

Regarding your specific question it says :

I recommend using a single capital letter for a generic type parameter. If you have no additional contextual information about the type parameter, you should use the letter T:

public class MyClass<T>
{...}

In all other cases, the official Microsoft guidelines for generic naming conventions are:

  • Name generic type parameters with descriptive names, unless a single letter name is completely self explanatory and a descriptive name would not add value.
public interface ISessionChannel<TSession> 
{...}
public delegate TOutput Converter<TInput,TOutput>(TInput from);
  • Consider indicating constraints placed on a type parameter in the name of parameter. For example, a parameter constrained to ISession may be called TSession.

Microsoft has an official guideline regarding generics : Names of Classes, Structs, and Interfaces (quoted here, and in book form : Framework Design Guidelines ).

Regarding your specific question it says :

Do name generic type parameters with descriptive names, unless a single-letter name is completely self explanatory and a descriptive name would not add value.

IDictionary<TKey, TValue> 

is an example of an interface that follows this guideline.

Consider using the letter T as the type parameter name for types with one single-letter type parameter.

Do prefix descriptive type parameter names with the letter T.

Consider indicating constraints placed on a type parameter in the name of parameter. For example, a parameter constrained to ISession may be called TSession.

Source Link
Matthieu
  • 4.6k
  • 2
  • 37
  • 38

Microsoft has an official guideline regarding generics here.

Regarding your specific question it says :

I recommend using a single capital letter for a generic type parameter. If you have no additional contextual information about the type parameter, you should use the letter T:

public class MyClass<T>
{...}

In all other cases, the official Microsoft guidelines for generic naming conventions are:

  • Name generic type parameters with descriptive names, unless a single letter name is completely self explanatory and a descriptive name would not add value.
public interface ISessionChannel<TSession> 
{...}
public delegate TOutput Converter<TInput,TOutput>(TInput from);
  • Consider indicating constraints placed on a type parameter in the name of parameter. For example, a parameter constrained to ISession may be called TSession.