ILookup vs. IGrouping

前端 未结 3 493
暖寄归人
暖寄归人 2020-11-28 23:15

I\'ve been having trouble articulating the differences between ILookup and IGrouping, and am curious if I understand it correctly now. L

3条回答
  •  旧巷少年郎
    2020-11-28 23:55

    Yes, all of those are correct.

    And ILookup also extends IEnumerable> so you can iterate over all the key/collection pairs as well as (or instead of) just looking up particular keys.

    I basically think of ILookup as being like IDictionary>.

    Bear in mind that ToLookup is a "do it now" operation (immediate execution) whereas a GroupBy is deferred. As it happens, with the way that "pull LINQ" works, when you start pulling IGroupings from the result of a GroupBy, it has to read all the data anyway (because you can't switch group midway through) whereas in other implementations it may be able to produce a streaming result. (It does in Push LINQ; I would expect LINQ to Events to be the same.)

提交回复
热议问题