Where does the C# generics naming convention come from?

冷暖自知 提交于 2019-12-01 15:44:25

问题


I understand T comes from Type, but why is it that the next variable often used is K?


回答1:


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>



回答2:


My guess would be that it's from Key.




回答3:


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>)



来源:https://stackoverflow.com/questions/4367939/where-does-the-c-sharp-generics-naming-convention-come-from

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!