ネットILookup <処理鍵、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