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

Published on July 28, 2013 by abundantcode

Filed under LINQ

Last modified July 28, 2013

Print this page

rate 1 star rate 2 star rate 3 star rate 4 star rate 5 star
Your rating: none, Average: 0 (0 votes)

This article have been viewed 9258 times

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();

}

}

}
0saves
If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

4 Comments

  1. Vishwas

    How to get the max value of a column which has type as char using LINQ ?

    Eg. for Column Value ITM108, ITM99, ITM102, Etc…

    December 30, 2013 - 10:30 am – Reply

  2. How to Get the Maximum value from a List of String using LINQ in C# ? | Abundant Code
    December 30, 2013 - 12:22 pm

Leave a Comment


x

You might be Interested in these Posts

VB.NET and LINQ – Filter elements from object collection with Logical Operators

Here’s a sample code snippet demonstrating how to filter elements from a list of objects using the w...

C# and LINQ – Filter elements from object collection with Logical Operators

Here’s a sample code snippet demonstrating how to filter elements from a list of objects using the w...

VB.NET and LINQ – Filter elements from object collection using where clause

Here’s a sample code snippet demonstrating how to filter elements from a list of objects using the w...