有没有办法平。净ILookup<TKey, TElement=""> 成一个名单<TElement>?
题
是否有一个快速的方式获得平 List<TElement>
从一个 ILookup<TKey, TElement>
这是创建 IEnumerable<TElement>
扩展?
更新的实例
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
然后再返回,将有可能改变了,但是。
其他提示
不知道这是什么你是之后。对于 Dictionary<>
要 List<>
List<TElement> list iLookUp.Values.ToList<TElement>();
从 List<>
要 Dictionary<>
var dict = list.Cast<TElement>().ToDictionary(t => t.Id, t => t.Description);
不隶属于 StackOverflow