Max

Input: IEnumerable<TSource>
Optional lambda expression:TSource => TResult

Max returns the smallest or largest element from a sequence:


using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main()
    {
        int[] numbers = { 28, 32, 14 };
        int largest = numbers.Max();  // 32;
        Console.WriteLine(largest);

    }
}

The output:


32

If you include a selector expression:


using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main()
    {
        int[] numbers = { 28, 32, 14 };
        int smallest = numbers.Max(n => n % 10);  // 8;
        Console.WriteLine(smallest);

    }
}

The output:


8
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.