We want to use Aggregation Operator Max in Linq. How to use this please help me.
Use Aggregation Operator Max in Linq. Norman Reedus 2192 21 Mar 2016 We want to use Aggregation Operator Max in Linq. How to use this please help me.
The Max operator returns the largest numeric element from a collection.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Prototype
{
class Example
{
static void Main()
{
IList<employee> List = new List<employee>() {
new employee() { id = 1, empname = "manoj", age = 18 } ,
new employee() { id = 2, empname = "stephan", age = 15 } ,
new employee() { id = 3, empname = "sivil", age = 25 } ,
new employee() { id = 4, empname = "mohan" , age = 20 } ,
new employee() { id = 5, empname = "johan" , age = 19 },
new employee() { id = 6, empname = "Ram" , age = 18 }
};
var maxAge = List.Max(s => s.age);
Console.WriteLine("Maximum Age of Employee: {0}", maxAge);
Console.ReadLine();
}
}
class employee
{
public int id { get; set; }
public string empname { get; set; }
public int age { get; set; }
}
}