C# Enumerable Max(IEnumerable)

Description

Returns the maximum value in a sequence of Int32 values.

Syntax


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

Parameters

  • source - A sequence of Int32 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.


// w  w w.j a v a 2 s .  c  o  m
using System;
using System.Linq;
using System.Collections.Generic;
public class MainClass{
  public static void Main(String[] argv){  
    List<long> longs = new List<long> { 123123123L, 46612335L, 8112325L };

    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