Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C#

Enumerable.Max: practical reference

Enumerable.Max: practical reference: Immediately enumerates and selects the greatest value or greatest selector result under the appropriate comparer.

Version: .NET LINQ; verified on .NET 10.0.14

Syntax

source.Max(/* overload-specific arguments */)

Immediately enumerates and selects the greatest value or greatest selector result under the appropriate comparer.

Use it for a maximum when the overload matches the type and null rules.

For float and double, NaN affects the result according to the overload contract. Custom types need a consistent comparison.

An empty non-nullable source throws InvalidOperationException; nullable and reference behavior depends on the overload.

The complete program actually uses Enumerable.Max; its exact expected stdout is 9.

Examples

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

Console.WriteLine(new[] { 3, 9, 4 }.Max());

Result

9

The complete program actually uses `Enumerable.Max`; its exact expected stdout is `9`.

Sources