LINQ Group By into a Dictionary Object

前端 未结 4 538
野的像风
野的像风 2021-01-30 02:07

I am trying to use LINQ to create a Dictionary> from a List. I can get this to work using \"

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-30 02:32

    For @atari2600, this is what the answer would look like using ToLookup in lambda syntax:

    var x = listOfCustomObjects
        .GroupBy(o => o.PropertyName)
        .ToLookup(customObject => customObject);
    

    Basically, it takes the IGrouping and materializes it for you into a dictionary of lists, with the values of PropertyName as the key.

提交回复
热议问题