{TOC}
| Namespace: | System.Linq |
| Assembly: | System.Core.dll |
| Extends: | IEnumerable<T> |
Back to
Standard Query Operator IndexEditIntroduction
The Min operator finds the minimum of a sequence of numeric values.
EditMethod Signatures
// 1 - Return the minimum value
public static decimal Min(
this IEnumerable<decimal> source)
public static double Min(
this IEnumerable<double> source)
public static int Min(
this IEnumerable<int> source)
public static TSource Min<TSource>(
this IEnumerable<TSource> source)
public static Nullable<int> Min(
this IEnumerable<Nullable<int>> source)
public static Nullable<double> Min(
this IEnumerable<Nullable<double>> source)
public static long Min(
this IEnumerable<long> source)
public static Nullable<decimal> Min(
this IEnumerable<Nullable<decimal>> source)
public static Nullable<long> Min(
this IEnumerable<Nullable<long>> source)
public static Nullable<float> Min(
this IEnumerable<Nullable<float>> source)
public static float Min(
this IEnumerable<float> source)
// 2 - Return the minimum value using the Select projector.
public static Nullable<int> Min<TSource>(
this IEnumerable<TSource> source,
Func<TSource, Nullable<int>> selector)
public static Nullable<long> Min<TSource>(
this IEnumerable<TSource> source,
Func<TSource, Nullable<long>> selector)
public static decimal Min<TSource>(
this IEnumerable<TSource> source,
Func<TSource, decimal> selector)
public static Nullable<float> Min<TSource>(
this IEnumerable<TSource> source,
Func<TSource, Nullable<float>> selector)
public static TResult Min<TSource, TResult>(
this IEnumerable<TSource> source,
Func<TSource, TResult> selector)
public static Nullable<decimal> Min<TSource>(
this IEnumerable<TSource> source,
Func<TSource, Nullable<decimal>> selector)
public static double Min<TSource>(
this IEnumerable<TSource> source,
Func<TSource, double> selector)
public static Nullable<double> Min<TSource>(
this IEnumerable<TSource> source,
Func<TSource, Nullable<double>> selector)
public static int Min<TSource>(
this IEnumerable<TSource> source,
Func<TSource, int> selector)
public static long Min<TSource>(
this IEnumerable<TSource> source,
Func<TSource, long> selector)
public static float Min<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 lowest value yet found, remember it.
Return the lowest 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.
If
selector is null, throw an ArgumentNullException.
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 lowest value yet found, remember it.
Return the lowest value found.
Note: If an element is null, then it is skipped in the count and does not affect the sum.
EditLoop Count
1. All elements from the source sequence are enumerated.
EditCode Samples
Min Operator Unit Tests