C# Enumerable Max(IEnumerable)

Description

Returns the maximum value in a sequence of Decimal values.

Syntax


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

Parameters

  • source - A sequence of Decimal 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 ww  . java  2s .com
using System;
using System.Linq;
using System.Collections.Generic;
public class MainClass{
  public static void Main(String[] argv){  
     List<long> longs = new List<long> { 123123123123L, 123123L, 123123L };

     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