> >> Under the bonnet, I suspect that LINQ-to-object uses ToLookup to perform
> >> GroupBy, but the difference is greater for other providers, such as a
[quoted text clipped - 10 lines]
> could you be so nice and provide an example where using GroupBy vs ToLookup
> would lead to different results?
For one thing (which I forgot to mention before), GroupBy uses deferred
execution whereas ToLookup uses immediate execution.
In other words, suppose you call GroupBy, then Console.WriteLine, then
foreach over the results - the Console.WriteLine will happen before the
grouping is actually executed.
If you call ToLookup, then Console.WriteLine, then foreach over the
results - the Console.WriteLine happens *after* all the grouping is
executed.

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk
wzychla@gmail.com - 03 Mar 2008 18:57 GMT
> For one thing (which I forgot to mention before), GroupBy uses deferred
> execution whereas ToLookup uses immediate execution.
that should be it - the docs says that conversion operators (ToList,
ToArray, ToLookup, ToDictionary) causes queries to be executed
immediately, where GroupBy can be, of course, deferred.
thanks, Jon.
Wiktor Zychla