LINQ Convert Dictionary to Lookup

前端 未结 4 1769
陌清茗
陌清茗 2020-12-16 11:57

I have a variable of type Dictionary>
I want to convert it to a Lookup.

<
4条回答
  •  感动是毒
    2020-12-16 12:44

    Same as Jon's method, but avoiding the creation of an anonymous type:

    var lookup = dictionary
                .SelectMany(p => p.Value, Tuple.Create)
                .ToLookup(p => p.Item1.Key, p => p.Item2);
    

提交回复
热议问题