[英]Where does the C# generics naming convention come from?
我知道T
来自Type
,但为什么经常使用的下一个变量是K
?
I've seen K
used for Key
but not frequently as the "next" type parameter. 我已经看到K
用于Key
但不经常用作“下一个”类型参数。 For example, you'll see 例如,你会看到
Dictionary<K, V>
where K
is for Key
and V
is for Value
. 其中K
代表Key
, V
代表Value
。
Sometimes you'll see T1
, T2
, etc. or T
, U
, V
(the former is preferred here). 有时你会看到T1
, T2
等,或者T
, U
, V
(前者在这里是首选)。 But I prefer more descriptive names like 但我更喜欢更具描述性的名字
Map<TSource, TDestination>
or 要么
Create<TUnitOfWork>
我的猜测是它来自Key
。
One more variation is the GenericFunction<T1,T2,TResult>
, where TResult is the type of value returned by the functon. 另一个变体是GenericFunction<T1,T2,TResult>
,其中TResult是功能返回的值的类型。 (as in, Func<T1,T2,...,TResult>
) (如, Func<T1,T2,...,TResult>
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.