{TOC}
| Namespace: | System.Linq |
| Assembly: | System.Core.dll |
| Extends: | IEnumerable<T> |
Back to
Standard Query Operator IndexEditIntroduction
The Max operator finds the maximum of a sequence of numeric values.
EditMethod Signatures
// 1 - Return the maximum value
public static Nullable<decimal> Max(
this IEnumerable<Nullable<decimal>> source)
public static long Max(
this IEnumerable<long> source)
public static TSource Max<TSource>(
this IEnumerable<TSource> source)
public static decimal Max(
this IEnumerable<decimal> source)
public static double Max(
this IEnumerable<double> source)
public static int Max(
this IEnumerable<int> source)
public static Nullable<double> Max(
this IEnumerable<Nullable<double>> source)
public static Nullable<int> Max(
this IEnumerable<Nullable<int>> source)
public static Nullable<long> Max(
this IEnumerable<Nullable<long>> source)
public static Nullable<float> Max(
this IEnumerable<Nullable<float>> source)
public static float Max(
this IEnumerable<float> source)
// 2 - Return the maximum value using the select projection.
public static TResult Max<TSource, TResult>(
this IEnumerable<TSource> source,
Func<TSource, TResult> selector)
public static Nullable<decimal> Max<TSource>(
this IEnumerable<TSource> source,
Func<TSource, Nullable<decimal>> selector)
public static Nullable<double> Max<TSource>(
this IEnumerable<TSource> source,
Func<TSource, Nullable<double>> selector)
public static decimal Max<TSource>(
this IEnumerable<TSource> source,
Func<TSource, decimal> selector)
public static double Max<TSource>(
this IEnumerable<TSource> source,
Func<TSource, double> selector)
public static int Max<TSource>(
this IEnumerable<TSource> source,
Func<TSource, int> selector)
public static long Max<TSource>(
this IEnumerable<TSource> source,
Func<TSource, long> selector)
public static Nullable<int> Max<TSource>(
this IEnumerable<TSource> source,
Func<TSource, Nullable<int>> selector)
public static Nullable<long> Max<TSource>(
this IEnumerable<TSource> source,
Func<TSource, Nullable<long>> selector)
public static Nullable<float> Max<TSource>(
this IEnumerable<TSource> source,
Func<TSource, Nullable<float>> selector)
public static float Max<TSource>(
this IEnumerable<TSource> source,
Func<TSource, float> selector)EditExceptions
Throws an ArgumentNullException if
source or
selector is null.
Throws an InvalidOperationException if
source has no elements and the TSource is not a nullable type.
EditPseudo-code
Overload 1
If
source is null, throw an ArgumentNullException.
If
source has no elements.
If the TSource is a nullable type.
Make the highest value a nullable TSource instance.
Else.
Throw an InvalidOperationException.
Iterate the
source sequence.
If the current element is not null.
If the current value is the first or highest value yet found, remember it.
Return The higest value found.
Overload 2
If
source is null, throw an ArgumentNullException.
If
source has no elements.
If the TSource is a nullable type.
Make the highest value a nullable TSource instance.
Else.
Throw an InvalidOperationException.
Iterate the
source sequence.
Get the current value by projecting the current element using the selector function.
If the current element is not null.
If the current value is the first or highest value yet found, remember it.
Return The highest value found.
EditLoop Count
1. All elements from the source sequence are enumerated.
EditCode Samples
MaxOperator Unit Tests