Ars*_*nko 1 .net c# ienumerable lazy-evaluation data-structures
我使用的结构可以表示为:
IEnumerable<KeyValuePair<TKey, TValue>>
Run Code Online (Sandbox Code Playgroud)
鉴于它写的时间太长(不计算代码分析可能会发出警告),我宁愿使用更具表现力的类型..NET Framework中是否有这样的类型,或者我应该创建自己的类型?
请注意,它与字典不同:
IDictionary<TKey, TValue> : IEnumerable<KeyValuePair<TKey, TValue>>
Run Code Online (Sandbox Code Playgroud)
因为字典确保每个键都是唯一的,这不是我的情况.我也不能使用查找:
Lookup<TKey, TValue> : IEnumerable<IGrouping<TKey, TValue>>
Run Code Online (Sandbox Code Playgroud)
因为查找不是懒惰的,即它需要刷新所有数据才能对其进行分组.
如果您有两个特定类型的键和值,您可以使用类型别名:
using PairSequence = System.Collections.Generic.IEnumerable<
System.Collections.Generic.KeyValuePair<string, int>>;
Run Code Online (Sandbox Code Playgroud)