linq Max

linq Max

Get the Min and Max value from a query.
public static void Max()
        {
            // Max - Simple
            int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };

            int maxNum = numbers.Max();

            Console.WriteLine("The maximum number is {0}.", maxNum);

            // Max - Projection
            string[] words = { "cherry", "apple", "blueberry" };

            int longestLength = words.Max(w => w.Length);

            Console.WriteLine("The longest word is {0} characters long.", longestLength);
        }
Output

linq Aggregate Operators
linq Max linq Max Reviewed by Bhaumik Patel on 6:28 PM Rating: 5