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 8054929
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T08:15:23+00:00 2026-06-05T08:15:23+00:00

I am going to be working with a collection that has about 500,000 items

  • 0

I am going to be working with a collection that has about 500,000 items in it and am looking for a decent way of getting all the duplicates. After looking through this post I see that the most popular solution is to use a hashed set. But what if I want to get all Cars that have the color red not just Car4 and Car5?

Car1.Color = Red;

Car2.Color = Blue;

Car3.Color = Green;

Car4.Color = Red;

Car5.Color = Red;

Given the problem what would be a reasonably fast way to do this?

EDIT:
I saw in that post that the code below could easily be changed to fit my needs. And I’m not sure there is really a better way to solve the problem but I will leave the post up just to see.

var duplicates = from car in cars
                 group car by car.Color into grouped
                 from car in grouped
                 select car;
  • 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-05T08:15:24+00:00Added an answer on June 5, 2026 at 8:15 am

    You can use the Enumerable.ToLookup Extension Method to group the cars by color and retrieve all cars of one color:

    var cars = new List<Car> { car1, car2, car3, car4, car5 };
    var lookup = cars.ToLookup(car => car.Color);
    var redCars = lookup[Red];
    // redCars == { car1, car4, car5 }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am going to start working on a website that has already been built
I am going to be working on a project that will heavily involve indexing
So working on getting my eclipse IDE going so I can develop my arduino
I'm working on a project that is going to be heavily templated, but the
I'm working on a server application that's going to work on Linux and Mac
I am working on a web application (LAMP stack) that has the code/dependencies for
Maybe I'm going about it the wrong way. Here is what I'm trying to
I'm working with an external framework (redmine) which has one Project model that has_many
So I'm currently working on a project that involves the collection and storing of
I have an application that has been getting strange errors when canceling out of

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.