I have some objects. And in each object there is a propety age. And I want to sort the property age of all the objects. And in this case I have two objects. But for example if you have three, four..etc objects. Maybe there is a more generic method for this?
So this is the code:
List<Person> personList = new List<Person>
{
new Person { Age = 77 },
new Person { Age = 88 },
new Person { Age = 1001 },
new Person { Age = 755 }
};
List<Dog> dogList = new List<Dog>
{
new Dog { Age = 1 },
new Dog { Age = 9 },
new Dog { Age = 10 },
new Dog { Age = 8 }
};
personList.Sort((x, y) => x.Age.CompareTo(y.Age));
dogList.Sort((x, y) => x.Age.CompareTo(y.Age));
So the output has to be in this case:
1 8 9 10 77 88 755 1001
geeksforgeeks quicksortor google