Get the Max value from objects array in C#
c#
Solution
The easiest way is to use LINQ:
using System.Linq;
var maxVal = people.Max(x => x.Age); // get highest age
var person = people.First(x => x.Age == maxVal); // get someone with such an age
Problem
I have an array which have objects, these objects have a string, a integer and a char properties. ``` Person[] people = new Person[1]; //Declare the array of objects [...] This code is irrelevant Person person = new Person(name, age, gender); //This creates instance a new object people.SetValue(person, i); //is just a variable which increase in a c Array.Resize(ref people, people.Length + 1); //Change array size i++; // Autoincrement ``` [...] More code to fill the values that works From all the objects person stored in people array, i want to get the person's age max value (age property is integer value)