How can I filter an array of objects to remove the ones that don't have the greatest value for Age grouped by IMCB first.
class Program
{
static void Main(string[] args)
{
Container[] containers = buildContainers();
// how can I get an array of containers that only contains the IMCB with the greatest Age.
// eg: [ {IMCB = "123456", Age = 3, Name = "third"}, {IMCB = "12345", Age = 4, Name = "fourth"} ]
}
static Container[] buildContainers()
{
List<Container> containers = new List<Container>();
containers.Add(new Container() { IMCB = "123456", Age = 1, Name = "first" });
containers.Add(new Container() { IMCB = "123456", Age = 3, Name = "third" });
containers.Add(new Container() { IMCB = "12345", Age = 2, Name = "second" });
containers.Add(new Container() { IMCB = "123456", Age = 2, Name = "second" });
containers.Add(new Container() { IMCB = "12345", Age = 4, Name = "fourth" });
return containers.ToArray();
}
}
class Container
{
public string Name { get; set; }
public string IMCB { get; set; }
public int Age { get; set; }
}