C# Enumerable Max(IEnumerable)

Description

Returns the maximum value in a sequence of Int64 values.

Syntax


public static long Max(
  this IEnumerable<long> source
)

Parameters

  • source - A sequence of Int64 values to determine the maximum value of.

Returns

returns The maximum value in the sequence.

Example

The following code example demonstrates how to use Max(IEnumerable) to determine the maximum value in a sequence.


/*from  www .j  av a 2  s  . c om*/
using System;
using System.Linq;
using System.Collections.Generic;
public class MainClass{
  public static void Main(String[] argv){  
      List<long> longs = new List<long> { 41236L, 46123135L, 81225L };

      long max = longs.Max();

      Console.WriteLine("The largest number is {0}.", max);

  }
}
    

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Linq »




Enumerable