Ani*_*Ani 15 .net c# dictionary coding-style naming-conventions
Dictionary<TKey, TValue>在.NET中是否有任何关于命名关联数组(例如)的约定/指南?
例如,有更好的方法来命名dict:
var dict = new Dictionary<Foo, Bar>();
Run Code Online (Sandbox Code Playgroud)
我用过/看过的一些名字:
foosToBars
mapFromFooToBar
barsByFoo
barsForFoos
Run Code Online (Sandbox Code Playgroud)
我还看到BCL中的某些类型选择"更好"的发音名称,这些名称并不直接揭示键和值应该表示的内容,例如在此方法中.
多图(例如ILookup<TKey, TElement>)如何?
编辑:
也许我的例子稍差; 我并不是要专注于键和值的类型.
如果它是这样的:
// key = Name of person, value = Age of person
var dict = new Dictionary<string, int>();
Run Code Online (Sandbox Code Playgroud)
样本更新为:
namesToAges
mapFromNameToAge
agesByName
agesForNames
Run Code Online (Sandbox Code Playgroud)
Rob*_*sor 11
我会尝试按照您链接的示例进行操作,您不会在其包含的内容之后命名字典,但您可以将其命名为它的用途.没过多久,有人确定"dict"是一个将Foo键映射到Bar值的字典,但我想知道的是你为什么要这样做.