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 11906 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

How to download a file from a URL using C#?

You can use the WebClient class in C# to download a file. How to download a file from a URL using C...

How to Create an Empty array without defining the size in C# ?

When we create an array in C# , we tend to define the size of the array as shown below. String[] st...

C++ Program to display "Hello, World!"

Problem Write a program in C++ to display "Hello, World!" on the screen. C++ Program to...