LINQ To SQL: Max operator


EmpDetails Table:

LinqTable.png


Code:

To find the Maximum Value in a Numeric Sequence.


using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
namespace
LINQ
{
class Program
{
static void Main(string[] args)
{
DataClassesDataContext dc = new DataClassesDataContext();
var maxSalary = (from emp in dc.EmpDetails
                 select emp.Salary).Max();
Console.WriteLine(maxSalary);
Console.Read();
}
}
}

Output:

80000
Next Recommended Reading LINQ To SQL: Sum operator