Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7812373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T04:29:01+00:00 2026-06-02T04:29:01+00:00

.ToLookup<TSource, TKey> returns an ILookup<TKey, TSource> . ILookup<TKey, TSource> also implements interface IEnumerable<IGrouping<TKey, TSource>>

  • 0

.ToLookup<TSource, TKey> returns an ILookup<TKey, TSource>. ILookup<TKey, TSource> also implements interface IEnumerable<IGrouping<TKey, TSource>>.

.GroupBy<TSource, TKey> returns an IEnumerable<IGrouping<Tkey, TSource>>.

ILookup has the handy indexer property, so it can be used in a dictionary-like (or lookup-like) manner, whereas GroupBy can’t. GroupBy without the indexer is a pain to work with; pretty much the only way you can then reference the return object is by looping through it (or using another LINQ-extension method). In other words, any case that GroupBy works, ToLookup will work as well.

All this leaves me with the question why would I ever bother with GroupBy? Why should it exist?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T04:29:02+00:00Added an answer on June 2, 2026 at 4:29 am

    why would I ever bother with GroupBy? Why should it exist?

    What happens when you call ToLookup on an object representing a remote database table with a billion rows in it?

    The billion rows are sent over the wire, and you build the lookup table locally.

    What happens when you call GroupBy on such an object?

    A query object is built; end of story.

    When that query object is enumerated then the analysis of the table is done on the database server and the grouped results are sent back on demand a few at a time.

    Logically they are the same thing but the performance implications of each are completely different. Calling ToLookup means I want a cache of the entire thing right now organized by group. Calling GroupBy means “I am building an object to represent the question ‘what would these things look like if I organized them by group?'”

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There is one method in Lookup<,> that is not in ILookup<,> : public IEnumerable<TResult>
I am writing a simple generic update extension for IEnumerable, this method used to
While I'm pretty certain that the keys are unordered when returned from linq's ToLookup
Problem I have a collection of XDocument instances. Each document has a repeated element
I've got an ILookup generated by some complicated expression. Let's say it's a lookup
What is the difference between LINQ ToDictionary and ToLookup? They seem to do the
Before .NET 3.5 was released, I use Dictionary<TKey, List<TValue>> for containing data. But I
I want to write an application which has 2 EJBs. This application can run
I have a Dictionary that has a signature: Dictionary<int, List<string>> . I'd like to
I have a Lookup that has a master list of priority levels and groups.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.