So, lets say I have a list of cars. Each item in the list has a brand and a color property. I would like to find out for each brand how many there are of the same color, and then print that info. The list will be filled by user input. There's no way for me to tell which exact values will be in the list.
Example:
class Car
{
public string brand;
public string color;
}
private void DoSomething()
{
List<Car> cars = new List<Car>();
cars.Add(new Car { brand = "Toyota", color = "blue" });
cars.Add(new Car { brand = "Toyota", color = "red" });
cars.Add(new Car { brand = "Toyota", color = "blue" });
cars.Add(new Car { brand = "Audi", color = "red" });
cars.Add(new Car { brand = "Audi", color = "red" });
cars.Add(new Car { brand = "Audi", color = "blue" });
// Find out for each brand how many there are of the same color, and then print that info
// Example output: Toyota: 2 blue, 1 red
// Audi: 2 red, 1 blue
}
I've spend a long time searching for a way to do this. All I was able to figure out was how to get the number of occurences of a certain item in the list.
If my question is unclear please let me know, I will try to explain a bit more.