[英]Is there a way to flatten a .Net ILookup<TKey, TElement> into a List<TElement>?
Is there a quick way to get a flattened List<TElement>
from an ILookup<TKey, TElement>
that was created from the IEnumerable<TElement>
extension? 有没有快速的方法从
ILookup<TKey, TElement>
中获取从IEnumerable<TElement>
扩展创建的扁平List<TElement>
?
Updated with example 更新了示例
List<int> list = new List<int>();
var lookup = list.ToLookup(key => key);
list = lookup.?? // How to convert the lookup back to the list
lookup.SelectMany( x => x ).ToList()
然而,向ILookup
转换回来很可能会改变顺序。
Not sure if this is what you are after. 不确定这是不是你想要的。 For
Dictionary<>
to List<>
对于
Dictionary<>
to List<>
List<TElement> list iLookUp.Values.ToList<TElement>();
from List<>
to Dictionary<>
从
List<>
到Dictionary<>
var dict = list.Cast<TElement>().ToDictionary(t => t.Id, t => t.Description);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.