Jer*_*acs 0 c# linq ienumerable grouping
这必须是重复的,但我的搜索并没有产生我想要的结果.
看起来这应该是相当简单的,但似乎没有内置的LINQ机制来实现这一点.一些帮助将不胜感激.
......我也可能做错了.我有一组具有属性的可枚举对象Foo,我想创建一个字典,其Foo属性是字典的键,其中值是具有Foo相同值的对象的枚举.
这应该工作:
var dict = yourGroup.ToDictionary(g=>g.Key, g=>g.Select(x=>x));
Run Code Online (Sandbox Code Playgroud)
或AsEnumerable用于生成值:
var dict = yourGroup.ToDictionary(g=>g.Key, g=>g.AsEnumerable());
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
781 次 |
| 最近记录: |