C# Queryable Max Method


Get the maximum value from a sequence using the Max() method.

Let’s say the following is our list.

List<long> list = new List<long> { 200, 400, 600, 800, 1000, 1200, 1400, 1600, 1800, 2000 };

Use the Max() method to get the largest element.

list.AsQueryable().Max();

Example

 Live Demo

using System;
using System.Collections.Generic;
using System.Linq;
class Demo {
   static void Main() {
      List<long> list = new List<long> { 200, 400, 600, 800, 1000, 1200, 1400, 1600, 1800, 2000 };
      foreach(long ele in list)
      Console.WriteLine(ele);
      // getting largest element
      long max_num = list.AsQueryable().Max();
      Console.WriteLine("Largest number = {0}", max_num);
   }
}

Output

200
400
600
800
1000
1200
1400
1600
1800
2000
Largest number = 2000

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 23-Jun-2020

122 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements