开发者

Where does the C# generics naming convention come from?

开发者 https://www.devze.com 2023-01-29 06:41 出处:网络
I understand T c开发者_JAVA百科omes from Type, but why is it that the next variable often used is K?I\'ve seen K used for Key but not frequently as the \"next\" type parameter. For example, you\'ll se

I understand T c开发者_JAVA百科omes from Type, but why is it that the next variable often used is K?


I've seen K used for Key but not frequently as the "next" type parameter. For example, you'll see

Dictionary<K, V>

where K is for Key and V is for Value.

Sometimes you'll see T1, T2, etc. or T, U, V (the former is preferred here). But I prefer more descriptive names like

Map<TSource, TDestination>

or

Create<TUnitOfWork>


My guess would be that it's from Key.


One more variation is the GenericFunction<T1,T2,TResult>, where TResult is the type of value returned by the functon. (as in, Func<T1,T2,...,TResult>)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号