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

}

}

}

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

C Program to convert lower case string to upper case

Problem Statement Write a program in C to convert the given string from lower case to upper case. ...

How to decode a base64 string in C#?

Here's a sample code snippet demonstrating how you can easily decode a base64 encoded string in C#. ...

How to disable editing of items in a combo box in c#?

When working in Win forms using C# and especially when you use the combo box , you would have notice...