Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ILookup versus IGrouping [duplicate]

Tags:

c#

linq

group-by

ILookup and IGrouping are pretty similar Linq interfaces. Both bound a key to a list of values.

The question is what differs these both interface.

Does anyone have an example what you can do with one type that you are not able to todo with the other one?

When should you use "group by" and when "to lookup"?

like image 887
rudimenter Avatar asked Sep 05 '10 19:09

rudimenter


1 Answers

You should call ToLookup if you need to lookup values by key, but you don't need ordering.

You should call GroupBy if you just need to loop through the groups.

like image 197
SLaks Avatar answered Sep 25 '22 19:09

SLaks