简体   繁体   English

转换iDictionary <TKey,TValue> 进入IDictionary <TSomeProperty, ICollection<TValue> &gt;

[英]Convert iDictionary<TKey,TValue> into IDictionary<TSomeProperty, ICollection<TValue>>

I have a IDictionary<TKey, TValue> referencing my items by a TKey hash. 我有一个IDictionary<TKey, TValue>通过TKey哈希引用我的项目。

How could I group by those values by, say, the result of EquivalenceClass TKey.GetEquivalenceClass() ? 我如何通过 EquivalenceClass TKey.GetEquivalenceClass()的结果对这些值进行EquivalenceClass TKey.GetEquivalenceClass() The result would then fit into a IDictionary<EquivalenceClass, ICollection<TValue>> 然后将结果放入IDictionary<EquivalenceClass, ICollection<TValue>>

A more concrete example, maybe: given 一个更具体的例子,也许是:给定

public enum PlayerPositionGroup {Attacker, Defender}
public class Player{
  public PlayerPositionGroup GetPositionGroup(){...}
}

turn

IDictionary<string, Player> SoccerPlayersByName

into 进入

IDictionary<PlayerPositionGroup, ICollection<Player>>

How about this: 这个怎么样:

SoccerPlayersByName
.Values
.GroupBy(v => v.GetPositionGroup())
.ToDictionary(g => g.Key, g => g.ToArray());

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何转换IDictionary <TKey, List<TValue> &gt;到IDictionary <TKey, IEnumerable<TValue> &gt;? - How to convert IDictionary<TKey, List<TValue> > to IDictionary<TKey, IEnumerable<TValue> >? 为什么IDictionary <TKey,TValue>扩展ICollection <KeyValuePair <TKey,TValue >>? - Why does IDictionary<TKey, TValue> extend ICollection<KeyValuePair<TKey, TValue>>? 推荐的转换IGrouping的方法 <TKey, TValue> 到IDictionary <TKey, IEnumerable<TValue> &gt; - Recommended way to convert IGrouping<TKey, TValue> to IDictionary<TKey, IEnumerable<TValue>> 为什么IDictionary <TKey,TValue>实现了ICollection和IEnumerable - Why IDictionary<TKey, TValue> implements both ICollection and IEnumerable ObservableDictionary类 <TKey, TValue> :IDictionary <TKey, TValue> 作为DataContract - class ObservableDictionary<TKey, TValue> : IDictionary<TKey, TValue> as DataContract IDictionary <TKey,TValue>替换值的实现和合同 - IDictionary<TKey, TValue> implementation and contract for replacing values 当方法具有IDictionary和IDictionary的重载时的不明确调用<TKey, TValue> - Ambiguous call when a method has overloads for IDictionary and IDictionary<TKey, TValue> 嵌套接口:演员表IDictionary <TKey, IList<TValue> &gt;到IDictionary <TKey, IEnumerable<TValue> &gt;? - Nested Interfaces: Cast IDictionary<TKey, IList<TValue>> to IDictionary<TKey, IEnumerable<TValue>>? 为什么不能/不能IDictionary <TKey,TValue>实现ILookup <TKey,TValue>? - Why doesn't/couldn't IDictionary<TKey,TValue> implement ILookup<TKey,TValue>? 为什么要向上转换IDictionary <TKey, TValue> 到IEnumerable <object> 失败? - Why does upcasting IDictionary<TKey, TValue> to IEnumerable<object> fail?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM