类型参数命名准则
务必使用描述性名称命名泛型类型参数,除非单个字母名称完全可以让人了解它表示的含义,而描述性名称不会有更多的意义。
public interface ISessionChannel { /…/ }
public delegate TOutput Converter<TInput, TOutput>(TInput from);
public class List { /…/ }
考虑使用 T 作为具有单个字母类型参数的类型的类型参数名。
public int IComparer() { return 0; }
public delegate bool Predicate(T item);
public struct Nullable where T : struct { /…/ }
务必将“T”作为描述性类型参数名的前缀。
public interface ISessionChannel
{
TSession Session { get; }
}
考虑在参数名中指示对此类型参数的约束。例如,可以将带有 ISession 约束的参数命名为 TSession。