How to Get the Max Value from a List of Integer using LINQ Query in C#?

One of the easiest way to get the Max value from a List of Integer in C# is to use LINQ extension method. The LINQ in C# provide the Max method which can be used to retrieve the Max Value from the List.

How to Get the Max Value from a List of Integer using LINQ Query in C#?

using System;

using System.Collections.Generic;

using System.Data;

using System.Linq;

namespace AbundantCode

{

internal class Program

{

// How to Get the Max Value from a List of Integer using LINQ Query in C#?

private static void Main(string[] args)

{

int[] Marks = new int[] { 1, 2, 8, 3, 10, 25, 4 };

// Get Max using LINQ Query

var result = (from m in Marks

select m).Max();

Console.WriteLine(result);

Console.ReadLine();

}

}

}
%d