Where does the C# generics naming convention come

2019-02-21 22:43发布

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

3条回答
Summer. ? 凉城
2楼-- · 2019-02-21 23:03

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>
查看更多
可以哭但决不认输i
3楼-- · 2019-02-21 23:25

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

查看更多
欢心
4楼-- · 2019-02-21 23:30

My guess would be that it's from Key.

查看更多
登录 后发表回答