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;
You can use the Enumerable.ToLookup Extension Method to group the cars by color and retrieve all cars of one color: