开发者

Is there a way to flatten a .Net ILookup<TKey, TElement> into a List<TElement>?

开发者 https://www.devze.com 2022-12-21 05:43 出处:网络
Is there a quick way to get a flattened List<TElement> from an ILookup<TKey, TElement> that was created from the IEnumerable<TElement> extension?

Is there a quick way to get a flattened List<TElement> from an ILookup<TKey, TElement> that was created from the IEnumerable<TElement> extension?


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()

The transformation to ILookup and back again will have most likely changed the order, however.


Not sure if this is what you are after. For Dictionary<> to List<>

List<TElement> list iLookUp.Values.ToList<TElement>();

from List<> to Dictionary<>

var dict = list.Cast<TElement>().ToDictionary(t => t.Id, t => t.Description);
0

精彩评论

暂无评论...
验证码 换一张
取 消