有没有办法平。净ILookup<TKey, TElement=""> 成一个名单<TElement>?

StackOverflow https://stackoverflow.com/questions/2323369

  •  22-09-2019
  •  | 
  •  

是否有一个快速的方式获得平 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);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top