Enumerable.Min Method

Definition

返回值序列中的最小值。Returns the minimum value in a sequence of values.

Overloads

Min(IEnumerable<Nullable<Int64>>)

返回可以为 null 的 Int64 值序列中的最小值。Returns the minimum value in a sequence of nullable Int64 values.

Min(IEnumerable<Nullable<Int32>>)

返回可以为 null 的 Int32 值序列中的最小值。Returns the minimum value in a sequence of nullable Int32 values.

Min(IEnumerable<Single>)

返回 Single 值序列中的最小值。Returns the minimum value in a sequence of Single values.

Min(IEnumerable<Nullable<Single>>)

返回可以为 null 的 Single 值序列中的最小值。Returns the minimum value in a sequence of nullable Single values.

Min(IEnumerable<Nullable<Double>>)

返回可以为 null 的 Double 值序列中的最小值。Returns the minimum value in a sequence of nullable Double values.

Min(IEnumerable<Double>)

返回 Double 值序列中的最小值。Returns the minimum value in a sequence of Double values.

Min(IEnumerable<Int64>)

返回 Int64 值序列中的最小值。Returns the minimum value in a sequence of Int64 values.

Min(IEnumerable<Int32>)

返回 Int32 值序列中的最小值。Returns the minimum value in a sequence of Int32 values.

Min(IEnumerable<Nullable<Decimal>>)

返回可以为 null 的 Decimal 值序列中的最小值。Returns the minimum value in a sequence of nullable Decimal values.

Min(IEnumerable<Decimal>)

返回 Decimal 值序列中的最小值。Returns the minimum value in a sequence of Decimal values.

Min<TSource,TResult>(IEnumerable<TSource>, Func<TSource,TResult>)

对序列中的每个元素调用转换函数,并返回最小结果值。Invokes a transform function on each element of a generic sequence and returns the minimum resulting value.

Min<TSource>(IEnumerable<TSource>, Func<TSource,Single>)

对序列中的每个元素调用转换函数,并返回最小的 Single 值。Invokes a transform function on each element of a sequence and returns the minimum Single value.

Min<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Single>>)

对序列中的每个元素调用转换函数,并返回可以为 null 的最小的 Single 值。Invokes a transform function on each element of a sequence and returns the minimum nullable Single value.

Min<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Int64>>)

对序列中的每个元素调用转换函数,并返回可以为 null 的最小的 Int64 值。Invokes a transform function on each element of a sequence and returns the minimum nullable Int64 value.

Min<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Int32>>)

对序列中的每个元素调用转换函数,并返回可以为 null 的最小的 Int32 值。Invokes a transform function on each element of a sequence and returns the minimum nullable Int32 value.

Min<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Double>>)

对序列中的每个元素调用转换函数,并返回可以为 null 的最小的 Double 值。Invokes a transform function on each element of a sequence and returns the minimum nullable Double value.

Min<TSource>(IEnumerable<TSource>, Func<TSource,Int64>)

对序列中的每个元素调用转换函数,并返回最小的 Int64 值。Invokes a transform function on each element of a sequence and returns the minimum Int64 value.

Min<TSource>(IEnumerable<TSource>, Func<TSource,Int32>)

对序列中的每个元素调用转换函数,并返回最小的 Int32 值。Invokes a transform function on each element of a sequence and returns the minimum Int32 value.

Min<TSource>(IEnumerable<TSource>, Func<TSource,Double>)

对序列中的每个元素调用转换函数,并返回最小的 Double 值。Invokes a transform function on each element of a sequence and returns the minimum Double value.

Min<TSource>(IEnumerable<TSource>, Func<TSource,Decimal>)

对序列中的每个元素调用转换函数,并返回最小的 Decimal 值。Invokes a transform function on each element of a sequence and returns the minimum Decimal value.

Min<TSource>(IEnumerable<TSource>)

返回泛型序列中的最小值。Returns the minimum value in a generic sequence.

Min<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Decimal>>)

对序列中的每个元素调用转换函数,并返回可以为 null 的最小的 Decimal 值。Invokes a transform function on each element of a sequence and returns the minimum nullable Decimal value.

Min(IEnumerable<Nullable<Int64>>)

返回可以为 null 的 Int64 值序列中的最小值。Returns the minimum value in a sequence of nullable Int64 values.

public:
[System::Runtime::CompilerServices::Extension]
 static Nullable<long> Min(System::Collections::Generic::IEnumerable<Nullable<long>> ^ source);
public static long? Min (this System.Collections.Generic.IEnumerable<Nullable<long>> source);
static member Min : seq<Nullable<int64>> -> Nullable<int64>
<Extension()>
Public Function Min (source As IEnumerable(Of Nullable(Of Long))) As Nullable(Of Long)

Parameters

source
IEnumerable<Nullable<Int64>>

要确定其最小值的可以为 null 的 Int64 值序列。A sequence of nullable Int64 values to determine the minimum value of.

Returns

Nullable<Int64>

一个与序列中的最小值相对应的值,该值的类型在 C# 中为 Nullable<Int64>,在 Visual Basic 中为 Nullable(Of Int64)A value of type Nullable<Int64> in C# or Nullable(Of Int64) in Visual Basic that corresponds to the minimum value in the sequence.

Exceptions

sourcenullsource is null.

Examples

下面的代码示例演示如何使用 Min(IEnumerable<Nullable<Int32>>) 来确定序列中的最小值。The following code example demonstrates how to use Min(IEnumerable<Nullable<Int32>>) to determine the minimum value in a sequence.

Note

此代码示例使用此重载方法的重载,该重载与本主题介绍的特定重载不同。This code example uses an overload of this overloaded method that is different from the specific overload that this topic describes. 若要将此示例扩展到此主题,请将源序列的元素替换为相应数字类型的元素。To extend the example to this topic, substitute the elements of the source sequence with elements of the appropriate numerical type.

int?[] grades = { 78, 92, null, 99, 37, 81 };

int? min = grades.Min();

Console.WriteLine("The lowest grade is {0}.", min);

/*
 This code produces the following output:

 The lowest grade is 37.
*/
Dim grades() As Nullable(Of Integer) = {78, 92, Nothing, 99, 37, 81}
Dim min As Nullable(Of Integer) = grades.Min()

' Display the output.
Console.WriteLine($"The lowest grade is {min}")

' This code produces the following output:
'
' The lowest grade is 37

Remarks

Min(IEnumerable<Nullable<Int64>>) 方法使用 IComparable<T>Int64 实现来比较值。The Min(IEnumerable<Nullable<Int64>>) method uses the Int64 implementation of IComparable<T> to compare values.

如果源序列为空或仅包含 null的值,则此函数将返回 nullIf the source sequence is empty or contains only values that are null, this function returns null.

在 Visual Basic 查询表达式语法中,Aggregate Into Min() 子句会转换为 Min调用。In Visual Basic query expression syntax, an Aggregate Into Min() clause translates to an invocation of Min.

See also

Min(IEnumerable<Nullable<Int32>>)

返回可以为 null 的 Int32 值序列中的最小值。Returns the minimum value in a sequence of nullable Int32 values.

public:
[System::Runtime::CompilerServices::Extension]
 static Nullable<int> Min(System::Collections::Generic::IEnumerable<Nullable<int>> ^ source);
public static int? Min (this System.Collections.Generic.IEnumerable<Nullable<int>> source);
static member Min : seq<Nullable<int>> -> Nullable<int>
<Extension()>
Public Function Min (source As IEnumerable(Of Nullable(Of Integer))) As Nullable(Of Integer)

Parameters

source
IEnumerable<Nullable<Int32>>

要确定其最小值的可以为 null 的 Int32 值序列。A sequence of nullable Int32 values to determine the minimum value of.

Returns

Nullable<Int32>

一个与序列中的最小值相对应的值,该值的类型在 C# 中为 Nullable<Int32>,在 Visual Basic 中为 Nullable(Of Int32)A value of type Nullable<Int32> in C# or Nullable(Of Int32) in Visual Basic that corresponds to the minimum value in the sequence.

Exceptions

sourcenullsource is null.

Examples

下面的代码示例演示如何使用 Min(IEnumerable<Nullable<Int32>>) 来确定序列中的最小值。The following code example demonstrates how to use Min(IEnumerable<Nullable<Int32>>) to determine the minimum value in a sequence.

int?[] grades = { 78, 92, null, 99, 37, 81 };

int? min = grades.Min();

Console.WriteLine("The lowest grade is {0}.", min);

/*
 This code produces the following output:

 The lowest grade is 37.
*/
Dim grades() As Nullable(Of Integer) = {78, 92, Nothing, 99, 37, 81}
Dim min As Nullable(Of Integer) = grades.Min()

' Display the output.
Console.WriteLine($"The lowest grade is {min}")

' This code produces the following output:
'
' The lowest grade is 37

Remarks

Min(IEnumerable<Nullable<Int32>>) 方法使用 IComparable<T>Int32 实现来比较值。The Min(IEnumerable<Nullable<Int32>>) method uses the Int32 implementation of IComparable<T> to compare values.

如果源序列为空或仅包含 null的值,则此函数将返回 nullIf the source sequence is empty or contains only values that are null, this function returns null.

在 Visual Basic 查询表达式语法中,Aggregate Into Min() 子句会转换为 Min调用。In Visual Basic query expression syntax, an Aggregate Into Min() clause translates to an invocation of Min.

See also

Min(IEnumerable<Single>)

返回 Single 值序列中的最小值。Returns the minimum value in a sequence of Single values.

public:
[System::Runtime::CompilerServices::Extension]
 static float Min(System::Collections::Generic::IEnumerable<float> ^ source);
public static float Min (this System.Collections.Generic.IEnumerable<float> source);
static member Min : seq<single> -> single
<Extension()>
Public Function Min (source As IEnumerable(Of Single)) As Single

Parameters

source
IEnumerable<Single>

要确定其最小值的 Single 值序列。A sequence of Single values to determine the minimum value of.

Returns

Single

序列中的最小值。The minimum value in the sequence.

Exceptions

sourcenullsource is null.

source 中不包含任何元素。source contains no elements.

Examples

下面的代码示例演示如何使用 Min(IEnumerable<Double>) 来确定序列中的最小值。The following code example demonstrates how to use Min(IEnumerable<Double>) to determine the minimum value in a sequence.

Note

此代码示例使用此重载方法的重载,该重载与本主题介绍的特定重载不同。This code example uses an overload of this overloaded method that is different from the specific overload that this topic describes. 若要将此示例扩展到此主题,请将源序列的元素替换为相应数字类型的元素。To extend the example to this topic, substitute the elements of the source sequence with elements of the appropriate numerical type.

double[] doubles = { 1.5E+104, 9E+103, -2E+103 };

double min = doubles.Min();

Console.WriteLine("The smallest number is {0}.", min);

/*
 This code produces the following output:

 The smallest number is -2E+103.
*/
' Create an array of double values.
Dim doubles() As Double = {1.5E+104, 9.0E+103, -2.0E+103}

' Determine the smallest number in the array.
Dim min As Double = doubles.Min()

' Display the result.
Console.WriteLine($"The smallest number is {min}")

' This code produces the following output:
'
' The smallest number is -2E+103

Remarks

Min(IEnumerable<Single>) 方法使用 IComparable<T>Single 实现来比较值。The Min(IEnumerable<Single>) method uses the Single implementation of IComparable<T> to compare values.

在 Visual Basic 查询表达式语法中,Aggregate Into Min() 子句会转换为 Min调用。In Visual Basic query expression syntax, an Aggregate Into Min() clause translates to an invocation of Min.

See also

Min(IEnumerable<Nullable<Single>>)

返回可以为 null 的 Single 值序列中的最小值。Returns the minimum value in a sequence of nullable Single values.

public:
[System::Runtime::CompilerServices::Extension]
 static Nullable<float> Min(System::Collections::Generic::IEnumerable<Nullable<float>> ^ source);
public static float? Min (this System.Collections.Generic.IEnumerable<Nullable<float>> source);
static member Min : seq<Nullable<single>> -> Nullable<single>
<Extension()>
Public Function Min (source As IEnumerable(Of Nullable(Of Single))) As Nullable(Of Single)

Parameters

source
IEnumerable<Nullable<Single>>

要确定其最小值的可以为 null 的 Single 值序列。A sequence of nullable Single values to determine the minimum value of.

Returns

Nullable<Single>

一个与序列中的最小值相对应的值,该值的类型在 C# 中为 Nullable<Single>,在 Visual Basic 中为 Nullable(Of Single)A value of type Nullable<Single> in C# or Nullable(Of Single) in Visual Basic that corresponds to the minimum value in the sequence.

Exceptions

sourcenullsource is null.

Examples

下面的代码示例演示如何使用 Min(IEnumerable<Nullable<Int32>>) 来确定序列中的最小值。The following code example demonstrates how to use Min(IEnumerable<Nullable<Int32>>) to determine the minimum value in a sequence.

Note

此代码示例使用此重载方法的重载,该重载与本主题介绍的特定重载不同。This code example uses an overload of this overloaded method that is different from the specific overload that this topic describes. 若要将此示例扩展到此主题,请将源序列的元素替换为相应数字类型的元素。To extend the example to this topic, substitute the elements of the source sequence with elements of the appropriate numerical type.

int?[] grades = { 78, 92, null, 99, 37, 81 };

int? min = grades.Min();

Console.WriteLine("The lowest grade is {0}.", min);

/*
 This code produces the following output:

 The lowest grade is 37.
*/
Dim grades() As Nullable(Of Integer) = {78, 92, Nothing, 99, 37, 81}
Dim min As Nullable(Of Integer) = grades.Min()

' Display the output.
Console.WriteLine($"The lowest grade is {min}")

' This code produces the following output:
'
' The lowest grade is 37

Remarks

Min(IEnumerable<Nullable<Single>>) 方法使用 IComparable<T>Single 实现来比较值。The Min(IEnumerable<Nullable<Single>>) method uses the Single implementation of IComparable<T> to compare values.

如果源序列为空或仅包含 null的值,则此函数将返回 nullIf the source sequence is empty or contains only values that are null, this function returns null.

在 Visual Basic 查询表达式语法中,Aggregate Into Min() 子句会转换为 Min调用。In Visual Basic query expression syntax, an Aggregate Into Min() clause translates to an invocation of Min.

See also

Min(IEnumerable<Nullable<Double>>)

返回可以为 null 的 Double 值序列中的最小值。Returns the minimum value in a sequence of nullable Double values.

public:
[System::Runtime::CompilerServices::Extension]
 static Nullable<double> Min(System::Collections::Generic::IEnumerable<Nullable<double>> ^ source);
public static double? Min (this System.Collections.Generic.IEnumerable<Nullable<double>> source);
static member Min : seq<Nullable<double>> -> Nullable<double>
<Extension()>
Public Function Min (source As IEnumerable(Of Nullable(Of Double))) As Nullable(Of Double)

Parameters

source
IEnumerable<Nullable<Double>>

要确定其最小值的可以为 null 的 Double 值序列。A sequence of nullable Double values to determine the minimum value of.

Returns

Nullable<Double>

一个与序列中的最小值相对应的值,该值的类型在 C# 中为 Nullable<Double>,在 Visual Basic 中为 Nullable(Of Double)A value of type Nullable<Double> in C# or Nullable(Of Double) in Visual Basic that corresponds to the minimum value in the sequence.

Exceptions

sourcenullsource is null.

Examples

下面的代码示例演示如何使用 Min(IEnumerable<Nullable<Int32>>) 来确定序列中的最小值。The following code example demonstrates how to use Min(IEnumerable<Nullable<Int32>>) to determine the minimum value in a sequence.

Note

此代码示例使用此重载方法的重载,该重载与本主题介绍的特定重载不同。This code example uses an overload of this overloaded method that is different from the specific overload that this topic describes. 若要将此示例扩展到此主题,请将源序列的元素替换为相应数字类型的元素。To extend the example to this topic, substitute the elements of the source sequence with elements of the appropriate numerical type.

int?[] grades = { 78, 92, null, 99, 37, 81 };

int? min = grades.Min();

Console.WriteLine("The lowest grade is {0}.", min);

/*
 This code produces the following output:

 The lowest grade is 37.
*/
Dim grades() As Nullable(Of Integer) = {78, 92, Nothing, 99, 37, 81}
Dim min As Nullable(Of Integer) = grades.Min()

' Display the output.
Console.WriteLine($"The lowest grade is {min}")

' This code produces the following output:
'
' The lowest grade is 37

Remarks

Min(IEnumerable<Nullable<Double>>) 方法使用 IComparable<T>Double 实现来比较值。The Min(IEnumerable<Nullable<Double>>) method uses the Double implementation of IComparable<T> to compare values.

如果源序列为空或仅包含 null的值,则此函数将返回 nullIf the source sequence is empty or contains only values that are null, this function returns null.

在 Visual Basic 查询表达式语法中,Aggregate Into Min() 子句会转换为 Min调用。In Visual Basic query expression syntax, an Aggregate Into Min() clause translates to an invocation of Min.

See also

Min(IEnumerable<Double>)

返回 Double 值序列中的最小值。Returns the minimum value in a sequence of Double values.

public:
[System::Runtime::CompilerServices::Extension]
 static double Min(System::Collections::Generic::IEnumerable<double> ^ source);
public static double Min (this System.Collections.Generic.IEnumerable<double> source);
static member Min : seq<double> -> double
<Extension()>
Public Function Min (source As IEnumerable(Of Double)) As Double

Parameters

source
IEnumerable<Double>

要确定其最小值的 Double 值序列。A sequence of Double values to determine the minimum value of.

Returns

Double

序列中的最小值。The minimum value in the sequence.

Exceptions

sourcenullsource is null.

source 中不包含任何元素。source contains no elements.

Examples

下面的代码示例演示如何使用 Min(IEnumerable<Double>) 来确定序列中的最小值。The following code example demonstrates how to use Min(IEnumerable<Double>) to determine the minimum value in a sequence.

double[] doubles = { 1.5E+104, 9E+103, -2E+103 };

double min = doubles.Min();

Console.WriteLine("The smallest number is {0}.", min);

/*
 This code produces the following output:

 The smallest number is -2E+103.
*/
' Create an array of double values.
Dim doubles() As Double = {1.5E+104, 9.0E+103, -2.0E+103}

' Determine the smallest number in the array.
Dim min As Double = doubles.Min()

' Display the result.
Console.WriteLine($"The smallest number is {min}")

' This code produces the following output:
'
' The smallest number is -2E+103

Remarks

Min(IEnumerable<Double>) 方法使用 IComparable<T>Double 实现来比较值。The Min(IEnumerable<Double>) method uses the Double implementation of IComparable<T> to compare values.

在 Visual Basic 查询表达式语法中,Aggregate Into Min() 子句会转换为 Min调用。In Visual Basic query expression syntax, an Aggregate Into Min() clause translates to an invocation of Min.

See also

Min(IEnumerable<Int64>)

返回 Int64 值序列中的最小值。Returns the minimum value in a sequence of Int64 values.

public:
[System::Runtime::CompilerServices::Extension]
 static long Min(System::Collections::Generic::IEnumerable<long> ^ source);
public static long Min (this System.Collections.Generic.IEnumerable<long> source);
static member Min : seq<int64> -> int64
<Extension()>
Public Function Min (source As IEnumerable(Of Long)) As Long

Parameters

source
IEnumerable<Int64>

要确定其最小值的 Int64 值序列。A sequence of Int64 values to determine the minimum value of.

Returns

Int64

序列中的最小值。The minimum value in the sequence.

Exceptions

sourcenullsource is null.

source 中不包含任何元素。source contains no elements.

Examples

下面的代码示例演示如何使用 Min(IEnumerable<Double>) 来确定序列中的最小值。The following code example demonstrates how to use Min(IEnumerable<Double>) to determine the minimum value in a sequence.

Note

此代码示例使用此重载方法的重载,该重载与本主题介绍的特定重载不同。This code example uses an overload of this overloaded method that is different from the specific overload that this topic describes. 若要将此示例扩展到此主题,请将源序列的元素替换为相应数字类型的元素。To extend the example to this topic, substitute the elements of the source sequence with elements of the appropriate numerical type.

double[] doubles = { 1.5E+104, 9E+103, -2E+103 };

double min = doubles.Min();

Console.WriteLine("The smallest number is {0}.", min);

/*
 This code produces the following output:

 The smallest number is -2E+103.
*/
' Create an array of double values.
Dim doubles() As Double = {1.5E+104, 9.0E+103, -2.0E+103}

' Determine the smallest number in the array.
Dim min As Double = doubles.Min()

' Display the result.
Console.WriteLine($"The smallest number is {min}")

' This code produces the following output:
'
' The smallest number is -2E+103

Remarks

Min(IEnumerable<Int64>) 方法使用 IComparable<T>Int64 实现来比较值。The Min(IEnumerable<Int64>) method uses the Int64 implementation of IComparable<T> to compare values.

在 Visual Basic 查询表达式语法中,Aggregate Into Min() 子句会转换为 Min调用。In Visual Basic query expression syntax, an Aggregate Into Min() clause translates to an invocation of Min.

See also

Min(IEnumerable<Int32>)

返回 Int32 值序列中的最小值。Returns the minimum value in a sequence of Int32 values.

public:
[System::Runtime::CompilerServices::Extension]
 static int Min(System::Collections::Generic::IEnumerable<int> ^ source);
public static int Min (this System.Collections.Generic.IEnumerable<int> source);
static member Min : seq<int> -> int
<Extension()>
Public Function Min (source As IEnumerable(Of Integer)) As Integer

Parameters

source
IEnumerable<Int32>

要确定其最小值的 Int32 值序列。A sequence of Int32 values to determine the minimum value of.

Returns

Int32

序列中的最小值。The minimum value in the sequence.

Exceptions

sourcenullsource is null.

source 中不包含任何元素。source contains no elements.

Examples

下面的代码示例演示如何使用 Min(IEnumerable<Double>) 来确定序列中的最小值。The following code example demonstrates how to use Min(IEnumerable<Double>) to determine the minimum value in a sequence.

Note

此代码示例使用此重载方法的重载,该重载与本主题介绍的特定重载不同。This code example uses an overload of this overloaded method that is different from the specific overload that this topic describes. 若要将此示例扩展到此主题,请将源序列的元素替换为相应数字类型的元素。To extend the example to this topic, substitute the elements of the source sequence with elements of the appropriate numerical type.

double[] doubles = { 1.5E+104, 9E+103, -2E+103 };

double min = doubles.Min();

Console.WriteLine("The smallest number is {0}.", min);

/*
 This code produces the following output:

 The smallest number is -2E+103.
*/
' Create an array of double values.
Dim doubles() As Double = {1.5E+104, 9.0E+103, -2.0E+103}

' Determine the smallest number in the array.
Dim min As Double = doubles.Min()

' Display the result.
Console.WriteLine($"The smallest number is {min}")

' This code produces the following output:
'
' The smallest number is -2E+103

Remarks

Min(IEnumerable<Int32>) 方法使用 IComparable<T>Int32 实现来比较值。The Min(IEnumerable<Int32>) method uses the Int32 implementation of IComparable<T> to compare values.

在 Visual Basic 查询表达式语法中,Aggregate Into Min() 子句会转换为 Min调用。In Visual Basic query expression syntax, an Aggregate Into Min() clause translates to an invocation of Min.

See also

Min(IEnumerable<Nullable<Decimal>>)

返回可以为 null 的 Decimal 值序列中的最小值。Returns the minimum value in a sequence of nullable Decimal values.

public:
[System::Runtime::CompilerServices::Extension]
 static Nullable<System::Decimal> Min(System::Collections::Generic::IEnumerable<Nullable<System::Decimal>> ^ source);
public static decimal? Min (this System.Collections.Generic.IEnumerable<Nullable<decimal>> source);
static member Min : seq<Nullable<decimal>> -> Nullable<decimal>
<Extension()>
Public Function Min (source As IEnumerable(Of Nullable(Of Decimal))) As Nullable(Of Decimal)

Parameters

source
IEnumerable<Nullable<Decimal>>

要确定其最小值的可以为 null 的 Decimal 值序列。A sequence of nullable Decimal values to determine the minimum value of.

Returns

Nullable<Decimal>

一个与序列中的最小值相对应的值,该值的类型在 C# 中为 Nullable<Decimal>,在 Visual Basic 中为 Nullable(Of Decimal)A value of type Nullable<Decimal> in C# or Nullable(Of Decimal) in Visual Basic that corresponds to the minimum value in the sequence.

Exceptions

sourcenullsource is null.

Examples

下面的代码示例演示如何使用 Min(IEnumerable<Nullable<Int32>>) 来确定序列中的最小值。The following code example demonstrates how to use Min(IEnumerable<Nullable<Int32>>) to determine the minimum value in a sequence.

Note

此代码示例使用此重载方法的重载,该重载与本主题介绍的特定重载不同。This code example uses an overload of this overloaded method that is different from the specific overload that this topic describes. 若要将此示例扩展到此主题,请将源序列的元素替换为相应数字类型的元素。To extend the example to this topic, substitute the elements of the source sequence with elements of the appropriate numerical type.

int?[] grades = { 78, 92, null, 99, 37, 81 };

int? min = grades.Min();

Console.WriteLine("The lowest grade is {0}.", min);

/*
 This code produces the following output:

 The lowest grade is 37.
*/
Dim grades() As Nullable(Of Integer) = {78, 92, Nothing, 99, 37, 81}
Dim min As Nullable(Of Integer) = grades.Min()

' Display the output.
Console.WriteLine($"The lowest grade is {min}")

' This code produces the following output:
'
' The lowest grade is 37

Remarks

Min(IEnumerable<Nullable<Decimal>>) 方法使用 IComparable<T>Decimal 实现来比较值。The Min(IEnumerable<Nullable<Decimal>>) method uses the Decimal implementation of IComparable<T> to compare values.

如果源序列为空或仅包含 null的值,则此函数将返回 nullIf the source sequence is empty or contains only values that are null, this function returns null.

在 Visual Basic 查询表达式语法中,Aggregate Into Min() 子句会转换为 Min调用。In Visual Basic query expression syntax, an Aggregate Into Min() clause translates to an invocation of Min.

See also

Min(IEnumerable<Decimal>)

返回 Decimal 值序列中的最小值。Returns the minimum value in a sequence of Decimal values.

public:
[System::Runtime::CompilerServices::Extension]
 static System::Decimal Min(System::Collections::Generic::IEnumerable<System::Decimal> ^ source);
public static decimal Min (this System.Collections.Generic.IEnumerable<decimal> source);
static member Min : seq<decimal> -> decimal
<Extension()>
Public Function Min (source As IEnumerable(Of Decimal)) As Decimal

Parameters

source
IEnumerable<Decimal>

要确定其最小值的 Decimal 值序列。A sequence of Decimal values to determine the minimum value of.

Returns

Decimal

序列中的最小值。The minimum value in the sequence.

Exceptions

sourcenullsource is null.

source 中不包含任何元素。source contains no elements.

Examples

下面的代码示例演示如何使用 Min(IEnumerable<Double>) 来确定序列中的最小值。The following code example demonstrates how to use Min(IEnumerable<Double>) to determine the minimum value in a sequence.

Note

此代码示例使用此重载方法的重载,该重载与本主题介绍的特定重载不同。This code example uses an overload of this overloaded method that is different from the specific overload that this topic describes. 若要将此示例扩展到此主题,请将源序列的元素替换为相应数字类型的元素。To extend the example to this topic, substitute the elements of the source sequence with elements of the appropriate numerical type.

double[] doubles = { 1.5E+104, 9E+103, -2E+103 };

double min = doubles.Min();

Console.WriteLine("The smallest number is {0}.", min);

/*
 This code produces the following output:

 The smallest number is -2E+103.
*/
' Create an array of double values.
Dim doubles() As Double = {1.5E+104, 9.0E+103, -2.0E+103}

' Determine the smallest number in the array.
Dim min As Double = doubles.Min()

' Display the result.
Console.WriteLine($"The smallest number is {min}")

' This code produces the following output:
'
' The smallest number is -2E+103

Remarks

Min(IEnumerable<Decimal>) 方法使用 IComparable<T>Decimal 实现来比较值。The Min(IEnumerable<Decimal>) method uses the Decimal implementation of IComparable<T> to compare values.

在 Visual Basic 查询表达式语法中,Aggregate Into Min() 子句会转换为 Min调用。In Visual Basic query expression syntax, an Aggregate Into Min() clause translates to an invocation of Min.

See also

Min<TSource,TResult>(IEnumerable<TSource>, Func<TSource,TResult>)

对序列中的每个元素调用转换函数,并返回最小结果值。Invokes a transform function on each element of a generic sequence and returns the minimum resulting value.

public:
generic <typename TSource, typename TResult>
[System::Runtime::CompilerServices::Extension]
 static TResult Min(System::Collections::Generic::IEnumerable<TSource> ^ source, Func<TSource, TResult> ^ selector);
public static TResult Min<TSource,TResult> (this System.Collections.Generic.IEnumerable<TSource> source, Func<TSource,TResult> selector);
static member Min : seq<'Source> * Func<'Source, 'Result> -> 'Result
<Extension()>
Public Function Min(Of TSource, TResult) (source As IEnumerable(Of TSource), selector As Func(Of TSource, TResult)) As TResult

Type Parameters

TSource

source 的元素类型。The type of the elements of source.

TResult

selector 返回的值的类型。The type of the value returned by selector.

Parameters

source
IEnumerable<TSource>

要确定其最小值的值序列。A sequence of values to determine the minimum value of.

selector
Func<TSource,TResult>

应用于每个元素的转换函数。A transform function to apply to each element.

Returns

TResult

序列中的最小值。The minimum value in the sequence.

Exceptions

sourceselectornullsource or selector is null.

Examples

下面的代码示例演示如何使用 Min<TSource>(IEnumerable<TSource>, Func<TSource,Int32>) 来确定投影值序列中的最小值。The following code example demonstrates how to use Min<TSource>(IEnumerable<TSource>, Func<TSource,Int32>) to determine the minimum value in a sequence of projected values.

Note

此代码示例使用此重载方法的重载,该重载与本主题介绍的特定重载不同。This code example uses an overload of this overloaded method that is different from the specific overload that this topic describes. 若要将此示例扩展到本主题,请更改 selector 函数体。To extend the example to this topic, change the body of the selector function.

class Pet
{
    public string Name { get; set; }
    public int Age { get; set; }
}

public static void MinEx4()
{
    Pet[] pets = { new Pet { Name="Barley", Age=8 },
                   new Pet { Name="Boots", Age=4 },
                   new Pet { Name="Whiskers", Age=1 } };

    int min = pets.Min(pet => pet.Age);

    Console.WriteLine("The youngest animal is age {0}.", min);
}

/*
 This code produces the following output:

 The youngest animal is age 1.
*/
Structure Pet
    Public Name As String
    Public Age As Integer
End Structure

Sub MinEx4()
    ' Create an array of Pet objects.
    Dim pets() As Pet = {New Pet With {.Name = "Barley", .Age = 8},
                     New Pet With {.Name = "Boots", .Age = 4},
                     New Pet With {.Name = "Whiskers", .Age = 1}}

    ' Find the youngest pet by passing a 
    ' lambda expression to the Min() method.
    Dim min As Integer = pets.Min(Function(pet) pet.Age)

    ' Display the result.
    Console.WriteLine($"The youngest pet is age {min}")
End Sub

' This code produces the following output:
'
' The youngest pet is age 1

Remarks

如果类型 TResult 实现 IComparable<T>,则此方法将使用该实现来比较值。If type TResult implements IComparable<T>, this method uses that implementation to compare values. 否则,如果类型 TResult 实现 IComparable,则该实现用于比较值。Otherwise, if type TResult implements IComparable, that implementation is used to compare values.

在 Visual Basic 查询表达式语法中,Aggregate Into Min() 子句会转换为 Min调用。In Visual Basic query expression syntax, an Aggregate Into Min() clause translates to an invocation of Min.

See also

Min<TSource>(IEnumerable<TSource>, Func<TSource,Single>)

对序列中的每个元素调用转换函数,并返回最小的 Single 值。Invokes a transform function on each element of a sequence and returns the minimum Single value.

public:
generic <typename TSource>
[System::Runtime::CompilerServices::Extension]
 static float Min(System::Collections::Generic::IEnumerable<TSource> ^ source, Func<TSource, float> ^ selector);
public static float Min<TSource> (this System.Collections.Generic.IEnumerable<TSource> source, Func<TSource,float> selector);
static member Min : seq<'Source> * Func<'Source, single> -> single
<Extension()>
Public Function Min(Of TSource) (source As IEnumerable(Of TSource), selector As Func(Of TSource, Single)) As Single

Type Parameters

TSource

source 的元素类型。The type of the elements of source.

Parameters

source
IEnumerable<TSource>

要确定其最小值的值序列。A sequence of values to determine the minimum value of.

selector
Func<TSource,Single>

应用于每个元素的转换函数。A transform function to apply to each element.

Returns

Single

序列中的最小值。The minimum value in the sequence.

Exceptions

sourceselectornullsource or selector is null.

source 中不包含任何元素。source contains no elements.

Examples

下面的代码示例演示如何使用 Min<TSource>(IEnumerable<TSource>, Func<TSource,Int32>) 来确定投影值序列中的最小值。The following code example demonstrates how to use Min<TSource>(IEnumerable<TSource>, Func<TSource,Int32>) to determine the minimum value in a sequence of projected values.

Note

此代码示例使用此重载方法的重载,该重载与本主题介绍的特定重载不同。This code example uses an overload of this overloaded method that is different from the specific overload that this topic describes. 若要将此示例扩展到本主题,请更改 selector 函数体。To extend the example to this topic, change the body of the selector function.

class Pet
{
    public string Name { get; set; }
    public int Age { get; set; }
}

public static void MinEx4()
{
    Pet[] pets = { new Pet { Name="Barley", Age=8 },
                   new Pet { Name="Boots", Age=4 },
                   new Pet { Name="Whiskers", Age=1 } };

    int min = pets.Min(pet => pet.Age);

    Console.WriteLine("The youngest animal is age {0}.", min);
}

/*
 This code produces the following output:

 The youngest animal is age 1.
*/
Structure Pet
    Public Name As String
    Public Age As Integer
End Structure

Sub MinEx4()
    ' Create an array of Pet objects.
    Dim pets() As Pet = {New Pet With {.Name = "Barley", .Age = 8},
                     New Pet With {.Name = "Boots", .Age = 4},
                     New Pet With {.Name = "Whiskers", .Age = 1}}

    ' Find the youngest pet by passing a 
    ' lambda expression to the Min() method.
    Dim min As Integer = pets.Min(Function(pet) pet.Age)

    ' Display the result.
    Console.WriteLine($"The youngest pet is age {min}")
End Sub

' This code produces the following output:
'
' The youngest pet is age 1

Remarks

Min<TSource>(IEnumerable<TSource>, Func<TSource,Single>) 方法使用 IComparable<T>Single 实现来比较值。The Min<TSource>(IEnumerable<TSource>, Func<TSource,Single>) method uses the Single implementation of IComparable<T> to compare values.

如果提供 selector,该函数将 source 的成员投影为数值类型(特别 Single),则可以将此方法应用于任意值序列。You can apply this method to a sequence of arbitrary values if you provide a function, selector, that projects the members of source into a numeric type, specifically Single.

在 Visual Basic 查询表达式语法中,Aggregate Into Min() 子句会转换为 Min调用。In Visual Basic query expression syntax, an Aggregate Into Min() clause translates to an invocation of Min.

See also

Min<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Single>>)

对序列中的每个元素调用转换函数,并返回可以为 null 的最小的 Single 值。Invokes a transform function on each element of a sequence and returns the minimum nullable Single value.

public:
generic <typename TSource>
[System::Runtime::CompilerServices::Extension]
 static Nullable<float> Min(System::Collections::Generic::IEnumerable<TSource> ^ source, Func<TSource, Nullable<float>> ^ selector);
public static float? Min<TSource> (this System.Collections.Generic.IEnumerable<TSource> source, Func<TSource,Nullable<float>> selector);
static member Min : seq<'Source> * Func<'Source, Nullable<single>> -> Nullable<single>
<Extension()>
Public Function Min(Of TSource) (source As IEnumerable(Of TSource), selector As Func(Of TSource, Nullable(Of Single))) As Nullable(Of Single)

Type Parameters

TSource

source 的元素类型。The type of the elements of source.

Parameters

source
IEnumerable<TSource>

要确定其最小值的值序列。A sequence of values to determine the minimum value of.

selector
Func<TSource,Nullable<Single>>

应用于每个元素的转换函数。A transform function to apply to each element.

Returns

Nullable<Single>

与序列中的最小值相对应的值,该值的类型在 C# 中为 Nullable<Single>,在 Visual Basic 中为 Nullable(Of Single)The value of type Nullable<Single> in C# or Nullable(Of Single) in Visual Basic that corresponds to the minimum value in the sequence.

Exceptions

sourceselectornullsource or selector is null.

Examples

下面的代码示例演示如何使用 Min<TSource>(IEnumerable<TSource>, Func<TSource,Int32>) 来确定投影值序列中的最小值。The following code example demonstrates how to use Min<TSource>(IEnumerable<TSource>, Func<TSource,Int32>) to determine the minimum value in a sequence of projected values.

Note

此代码示例使用此重载方法的重载,该重载与本主题介绍的特定重载不同。This code example uses an overload of this overloaded method that is different from the specific overload that this topic describes. 若要将此示例扩展到本主题,请更改 selector 函数体。To extend the example to this topic, change the body of the selector function.

class Pet
{
    public string Name { get; set; }
    public int Age { get; set; }
}

public static void MinEx4()
{
    Pet[] pets = { new Pet { Name="Barley", Age=8 },
                   new Pet { Name="Boots", Age=4 },
                   new Pet { Name="Whiskers", Age=1 } };

    int min = pets.Min(pet => pet.Age);

    Console.WriteLine("The youngest animal is age {0}.", min);
}

/*
 This code produces the following output:

 The youngest animal is age 1.
*/
Structure Pet
    Public Name As String
    Public Age As Integer
End Structure

Sub MinEx4()
    ' Create an array of Pet objects.
    Dim pets() As Pet = {New Pet With {.Name = "Barley", .Age = 8},
                     New Pet With {.Name = "Boots", .Age = 4},
                     New Pet With {.Name = "Whiskers", .Age = 1}}

    ' Find the youngest pet by passing a 
    ' lambda expression to the Min() method.
    Dim min As Integer = pets.Min(Function(pet) pet.Age)

    ' Display the result.
    Console.WriteLine($"The youngest pet is age {min}")
End Sub

' This code produces the following output:
'
' The youngest pet is age 1

Remarks

Min<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Single>>) 方法使用 IComparable<T>Single 实现来比较值。The Min<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Single>>) method uses the Single implementation of IComparable<T> to compare values.

如果您提供了一个函数(selector),该函数将 source 的成员投影到一个数值类型中,特别是在C# Visual Basic 中 Nullable<Single>Nullable(Of Single),则可以将此方法应用于任意值序列。You can apply this method to a sequence of arbitrary values if you provide a function, selector, that projects the members of source into a numeric type, specifically Nullable<Single> in C# or Nullable(Of Single) in Visual Basic.

在 Visual Basic 查询表达式语法中,Aggregate Into Min() 子句会转换为 Min调用。In Visual Basic query expression syntax, an Aggregate Into Min() clause translates to an invocation of Min.

See also

Min<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Int64>>)

对序列中的每个元素调用转换函数,并返回可以为 null 的最小的 Int64 值。Invokes a transform function on each element of a sequence and returns the minimum nullable Int64 value.

public:
generic <typename TSource>
[System::Runtime::CompilerServices::Extension]
 static Nullable<long> Min(System::Collections::Generic::IEnumerable<TSource> ^ source, Func<TSource, Nullable<long>> ^ selector);
public static long? Min<TSource> (this System.Collections.Generic.IEnumerable<TSource> source, Func<TSource,Nullable<long>> selector);
static member Min : seq<'Source> * Func<'Source, Nullable<int64>> -> Nullable<int64>
<Extension()>
Public Function Min(Of TSource) (source As IEnumerable(Of TSource), selector As Func(Of TSource, Nullable(Of Long))) As Nullable(Of Long)

Type Parameters

TSource

source 的元素类型。The type of the elements of source.

Parameters

source
IEnumerable<TSource>

要确定其最小值的值序列。A sequence of values to determine the minimum value of.

selector
Func<TSource,Nullable<Int64>>

应用于每个元素的转换函数。A transform function to apply to each element.

Returns

Nullable<Int64>

与序列中的最小值相对应的值,该值的类型在 C# 中为 Nullable<Int64>,在 Visual Basic 中为 Nullable(Of Int64)The value of type Nullable<Int64> in C# or Nullable(Of Int64) in Visual Basic that corresponds to the minimum value in the sequence.

Exceptions

sourceselectornullsource or selector is null.

Examples

下面的代码示例演示如何使用 Min<TSource>(IEnumerable<TSource>, Func<TSource,Int32>) 来确定投影值序列中的最小值。The following code example demonstrates how to use Min<TSource>(IEnumerable<TSource>, Func<TSource,Int32>) to determine the minimum value in a sequence of projected values.

Note

此代码示例使用此重载方法的重载,该重载与本主题介绍的特定重载不同。This code example uses an overload of this overloaded method that is different from the specific overload that this topic describes. 若要将此示例扩展到本主题,请更改 selector 函数体。To extend the example to this topic, change the body of the selector function.

class Pet
{
    public string Name { get; set; }
    public int Age { get; set; }
}

public static void MinEx4()
{
    Pet[] pets = { new Pet { Name="Barley", Age=8 },
                   new Pet { Name="Boots", Age=4 },
                   new Pet { Name="Whiskers", Age=1 } };

    int min = pets.Min(pet => pet.Age);

    Console.WriteLine("The youngest animal is age {0}.", min);
}

/*
 This code produces the following output:

 The youngest animal is age 1.
*/
Structure Pet
    Public Name As String
    Public Age As Integer
End Structure

Sub MinEx4()
    ' Create an array of Pet objects.
    Dim pets() As Pet = {New Pet With {.Name = "Barley", .Age = 8},
                     New Pet With {.Name = "Boots", .Age = 4},
                     New Pet With {.Name = "Whiskers", .Age = 1}}

    ' Find the youngest pet by passing a 
    ' lambda expression to the Min() method.
    Dim min As Integer = pets.Min(Function(pet) pet.Age)

    ' Display the result.
    Console.WriteLine($"The youngest pet is age {min}")
End Sub

' This code produces the following output:
'
' The youngest pet is age 1

Remarks

Min<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Int64>>) 方法使用 IComparable<T>Int64 实现来比较值。The Min<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Int64>>) method uses the Int64 implementation of IComparable<T> to compare values.

如果您提供了一个函数(selector),该函数将 source 的成员投影到一个数值类型中,特别是在C# Visual Basic 中 Nullable<Int64>Nullable(Of Int64),则可以将此方法应用于任意值序列。You can apply this method to a sequence of arbitrary values if you provide a function, selector, that projects the members of source into a numeric type, specifically Nullable<Int64> in C# or Nullable(Of Int64) in Visual Basic.

在 Visual Basic 查询表达式语法中,Aggregate Into Min() 子句会转换为 Min调用。In Visual Basic query expression syntax, an Aggregate Into Min() clause translates to an invocation of Min.

See also

Min<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Int32>>)

对序列中的每个元素调用转换函数,并返回可以为 null 的最小的 Int32 值。Invokes a transform function on each element of a sequence and returns the minimum nullable Int32 value.

public:
generic <typename TSource>
[System::Runtime::CompilerServices::Extension]
 static Nullable<int> Min(System::Collections::Generic::IEnumerable<TSource> ^ source, Func<TSource, Nullable<int>> ^ selector);
public static int? Min<TSource> (this System.Collections.Generic.IEnumerable<TSource> source, Func<TSource,Nullable<int>> selector);
static member Min : seq<'Source> * Func<'Source, Nullable<int>> -> Nullable<int>
<Extension()>
Public Function Min(Of TSource) (source As IEnumerable(Of TSource), selector As Func(Of TSource, Nullable(Of Integer))) As Nullable(Of Integer)

Type Parameters

TSource

source 的元素类型。The type of the elements of source.

Parameters

source
IEnumerable<TSource>

要确定其最小值的值序列。A sequence of values to determine the minimum value of.

selector
Func<TSource,Nullable<Int32>>

应用于每个元素的转换函数。A transform function to apply to each element.

Returns

Nullable<Int32>

与序列中的最小值相对应的值,该值的类型在 C# 中为 Nullable<Int32>,在 Visual Basic 中为 Nullable(Of Int32)The value of type Nullable<Int32> in C# or Nullable(Of Int32) in Visual Basic that corresponds to the minimum value in the sequence.

Exceptions

sourceselectornullsource or selector is null.

Examples

下面的代码示例演示如何使用 Min<TSource>(IEnumerable<TSource>, Func<TSource,Int32>) 来确定投影值序列中的最小值。The following code example demonstrates how to use Min<TSource>(IEnumerable<TSource>, Func<TSource,Int32>) to determine the minimum value in a sequence of projected values.

Note

此代码示例使用此重载方法的重载,该重载与本主题介绍的特定重载不同。This code example uses an overload of this overloaded method that is different from the specific overload that this topic describes. 若要将此示例扩展到本主题,请更改 selector 函数体。To extend the example to this topic, change the body of the selector function.

class Pet
{
    public string Name { get; set; }
    public int Age { get; set; }
}

public static void MinEx4()
{
    Pet[] pets = { new Pet { Name="Barley", Age=8 },
                   new Pet { Name="Boots", Age=4 },
                   new Pet { Name="Whiskers", Age=1 } };

    int min = pets.Min(pet => pet.Age);

    Console.WriteLine("The youngest animal is age {0}.", min);
}

/*
 This code produces the following output:

 The youngest animal is age 1.
*/
Structure Pet
    Public Name As String
    Public Age As Integer
End Structure

Sub MinEx4()
    ' Create an array of Pet objects.
    Dim pets() As Pet = {New Pet With {.Name = "Barley", .Age = 8},
                     New Pet With {.Name = "Boots", .Age = 4},
                     New Pet With {.Name = "Whiskers", .Age = 1}}

    ' Find the youngest pet by passing a 
    ' lambda expression to the Min() method.
    Dim min As Integer = pets.Min(Function(pet) pet.Age)

    ' Display the result.
    Console.WriteLine($"The youngest pet is age {min}")
End Sub

' This code produces the following output:
'
' The youngest pet is age 1

Remarks

Min<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Int32>>) 方法使用 IComparable<T>Int32 实现来比较值。The Min<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Int32>>) method uses the Int32 implementation of IComparable<T> to compare values.

如果提供了一个函数(selector),该函数将源的成员投影到数值类型中,特别是在C# Visual Basic 中 Nullable<Int32>Nullable(Of Int32),则可以将此方法应用于任意值序列。You can apply this method to a sequence of arbitrary values if you provide a function, selector, that projects the members of source into a numeric type, specifically Nullable<Int32> in C# or Nullable(Of Int32) in Visual Basic.

在 Visual Basic 查询表达式语法中,Aggregate Into Min() 子句会转换为 Min调用。In Visual Basic query expression syntax, an Aggregate Into Min() clause translates to an invocation of Min.

See also

Min<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Double>>)

对序列中的每个元素调用转换函数,并返回可以为 null 的最小的 Double 值。Invokes a transform function on each element of a sequence and returns the minimum nullable Double value.

public:
generic <typename TSource>
[System::Runtime::CompilerServices::Extension]
 static Nullable<double> Min(System::Collections::Generic::IEnumerable<TSource> ^ source, Func<TSource, Nullable<double>> ^ selector);
public static double? Min<TSource> (this System.Collections.Generic.IEnumerable<TSource> source, Func<TSource,Nullable<double>> selector);
static member Min : seq<'Source> * Func<'Source, Nullable<double>> -> Nullable<double>
<Extension()>
Public Function Min(Of TSource) (source As IEnumerable(Of TSource), selector As Func(Of TSource, Nullable(Of Double))) As Nullable(Of Double)

Type Parameters

TSource

source 的元素类型。The type of the elements of source.

Parameters

source
IEnumerable<TSource>

要确定其最小值的值序列。A sequence of values to determine the minimum value of.

selector
Func<TSource,Nullable<Double>>

应用于每个元素的转换函数。A transform function to apply to each element.

Returns

Nullable<Double>

与序列中的最小值相对应的值,该值的类型在 C# 中为 Nullable<Double>,在 Visual Basic 中为 Nullable(Of Double)The value of type Nullable<Double> in C# or Nullable(Of Double) in Visual Basic that corresponds to the minimum value in the sequence.

Exceptions

sourceselectornullsource or selector is null.

Examples

下面的代码示例演示如何使用 Min<TSource>(IEnumerable<TSource>, Func<TSource,Int32>) 来确定投影值序列中的最小值。The following code example demonstrates how to use Min<TSource>(IEnumerable<TSource>, Func<TSource,Int32>) to determine the minimum value in a sequence of projected values.

Note

此代码示例使用此重载方法的重载,该重载与本主题介绍的特定重载不同。This code example uses an overload of this overloaded method that is different from the specific overload that this topic describes. 若要将此示例扩展到本主题,请更改 selector 函数体。To extend the example to this topic, change the body of the selector function.

class Pet
{
    public string Name { get; set; }
    public int Age { get; set; }
}

public static void MinEx4()
{
    Pet[] pets = { new Pet { Name="Barley", Age=8 },
                   new Pet { Name="Boots", Age=4 },
                   new Pet { Name="Whiskers", Age=1 } };

    int min = pets.Min(pet => pet.Age);

    Console.WriteLine("The youngest animal is age {0}.", min);
}

/*
 This code produces the following output:

 The youngest animal is age 1.
*/
Structure Pet
    Public Name As String
    Public Age As Integer
End Structure

Sub MinEx4()
    ' Create an array of Pet objects.
    Dim pets() As Pet = {New Pet With {.Name = "Barley", .Age = 8},
                     New Pet With {.Name = "Boots", .Age = 4},
                     New Pet With {.Name = "Whiskers", .Age = 1}}

    ' Find the youngest pet by passing a 
    ' lambda expression to the Min() method.
    Dim min As Integer = pets.Min(Function(pet) pet.Age)

    ' Display the result.
    Console.WriteLine($"The youngest pet is age {min}")
End Sub

' This code produces the following output:
'
' The youngest pet is age 1

Remarks

Min<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Double>>) 方法使用 IComparable<T>Double 实现来比较值。The Min<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Double>>) method uses the Double implementation of IComparable<T> to compare values.

如果您提供了一个函数(selector),该函数将 source 的成员投影到一个数值类型中,特别是在C# Visual Basic 中 Nullable<Double>Nullable(Of Double),则可以将此方法应用于任意值序列。You can apply this method to a sequence of arbitrary values if you provide a function, selector, that projects the members of source into a numeric type, specifically Nullable<Double> in C# or Nullable(Of Double) in Visual Basic.

在 Visual Basic 查询表达式语法中,Aggregate Into Min() 子句会转换为 Min调用。In Visual Basic query expression syntax, an Aggregate Into Min() clause translates to an invocation of Min.

See also

Min<TSource>(IEnumerable<TSource>, Func<TSource,Int64>)

对序列中的每个元素调用转换函数,并返回最小的 Int64 值。Invokes a transform function on each element of a sequence and returns the minimum Int64 value.

public:
generic <typename TSource>
[System::Runtime::CompilerServices::Extension]
 static long Min(System::Collections::Generic::IEnumerable<TSource> ^ source, Func<TSource, long> ^ selector);
public static long Min<TSource> (this System.Collections.Generic.IEnumerable<TSource> source, Func<TSource,long> selector);
static member Min : seq<'Source> * Func<'Source, int64> -> int64
<Extension()>
Public Function Min(Of TSource) (source As IEnumerable(Of TSource), selector As Func(Of TSource, Long)) As Long

Type Parameters

TSource

source 的元素类型。The type of the elements of source.

Parameters

source
IEnumerable<TSource>

要确定其最小值的值序列。A sequence of values to determine the minimum value of.

selector
Func<TSource,Int64>

应用于每个元素的转换函数。A transform function to apply to each element.

Returns

Int64

序列中的最小值。The minimum value in the sequence.

Exceptions

sourceselectornullsource or selector is null.

source 中不包含任何元素。source contains no elements.

Examples

下面的代码示例演示如何使用 Min<TSource>(IEnumerable<TSource>, Func<TSource,Int32>) 来确定投影值序列中的最小值。The following code example demonstrates how to use Min<TSource>(IEnumerable<TSource>, Func<TSource,Int32>) to determine the minimum value in a sequence of projected values.

Note

此代码示例使用此重载方法的重载,该重载与本主题介绍的特定重载不同。This code example uses an overload of this overloaded method that is different from the specific overload that this topic describes. 若要将此示例扩展到本主题,请更改 selector 函数体。To extend the example to this topic, change the body of the selector function.

class Pet
{
    public string Name { get; set; }
    public int Age { get; set; }
}

public static void MinEx4()
{
    Pet[] pets = { new Pet { Name="Barley", Age=8 },
                   new Pet { Name="Boots", Age=4 },
                   new Pet { Name="Whiskers", Age=1 } };

    int min = pets.Min(pet => pet.Age);

    Console.WriteLine("The youngest animal is age {0}.", min);
}

/*
 This code produces the following output:

 The youngest animal is age 1.
*/
Structure Pet
    Public Name As String
    Public Age As Integer
End Structure

Sub MinEx4()
    ' Create an array of Pet objects.
    Dim pets() As Pet = {New Pet With {.Name = "Barley", .Age = 8},
                     New Pet With {.Name = "Boots", .Age = 4},
                     New Pet With {.Name = "Whiskers", .Age = 1}}

    ' Find the youngest pet by passing a 
    ' lambda expression to the Min() method.
    Dim min As Integer = pets.Min(Function(pet) pet.Age)

    ' Display the result.
    Console.WriteLine($"The youngest pet is age {min}")
End Sub

' This code produces the following output:
'
' The youngest pet is age 1

Remarks

Min<TSource>(IEnumerable<TSource>, Func<TSource,Int64>) 方法使用 IComparable<T>Int64 实现来比较值。The Min<TSource>(IEnumerable<TSource>, Func<TSource,Int64>) method uses the Int64 implementation of IComparable<T> to compare values.

如果提供 selector,该函数将 source 的成员投影为数值类型(特别 Int64),则可以将此方法应用于任意值序列。You can apply this method to a sequence of arbitrary values if you provide a function, selector, that projects the members of source into a numeric type, specifically Int64.

在 Visual Basic 查询表达式语法中,Aggregate Into Min() 子句会转换为 Min调用。In Visual Basic query expression syntax, an Aggregate Into Min() clause translates to an invocation of Min.

See also

Min<TSource>(IEnumerable<TSource>, Func<TSource,Int32>)

对序列中的每个元素调用转换函数,并返回最小的 Int32 值。Invokes a transform function on each element of a sequence and returns the minimum Int32 value.

public:
generic <typename TSource>
[System::Runtime::CompilerServices::Extension]
 static int Min(System::Collections::Generic::IEnumerable<TSource> ^ source, Func<TSource, int> ^ selector);
public static int Min<TSource> (this System.Collections.Generic.IEnumerable<TSource> source, Func<TSource,int> selector);
static member Min : seq<'Source> * Func<'Source, int> -> int
<Extension()>
Public Function Min(Of TSource) (source As IEnumerable(Of TSource), selector As Func(Of TSource, Integer)) As Integer

Type Parameters

TSource

source 的元素类型。The type of the elements of source.

Parameters

source
IEnumerable<TSource>

要确定其最小值的值序列。A sequence of values to determine the minimum value of.

selector
Func<TSource,Int32>

应用于每个元素的转换函数。A transform function to apply to each element.

Returns

Int32

序列中的最小值。The minimum value in the sequence.

Exceptions

sourceselectornullsource or selector is null.

source 中不包含任何元素。source contains no elements.

Examples

下面的代码示例演示如何使用 Min<TSource>(IEnumerable<TSource>, Func<TSource,Int32>) 来确定投影值序列中的最小值。The following code example demonstrates how to use Min<TSource>(IEnumerable<TSource>, Func<TSource,Int32>) to determine the minimum value in a sequence of projected values.

class Pet
{
    public string Name { get; set; }
    public int Age { get; set; }
}

public static void MinEx4()
{
    Pet[] pets = { new Pet { Name="Barley", Age=8 },
                   new Pet { Name="Boots", Age=4 },
                   new Pet { Name="Whiskers", Age=1 } };

    int min = pets.Min(pet => pet.Age);

    Console.WriteLine("The youngest animal is age {0}.", min);
}

/*
 This code produces the following output:

 The youngest animal is age 1.
*/
Structure Pet
    Public Name As String
    Public Age As Integer
End Structure

Sub MinEx4()
    ' Create an array of Pet objects.
    Dim pets() As Pet = {New Pet With {.Name = "Barley", .Age = 8},
                     New Pet With {.Name = "Boots", .Age = 4},
                     New Pet With {.Name = "Whiskers", .Age = 1}}

    ' Find the youngest pet by passing a 
    ' lambda expression to the Min() method.
    Dim min As Integer = pets.Min(Function(pet) pet.Age)

    ' Display the result.
    Console.WriteLine($"The youngest pet is age {min}")
End Sub

' This code produces the following output:
'
' The youngest pet is age 1

Remarks

Min<TSource>(IEnumerable<TSource>, Func<TSource,Int32>) 方法使用 IComparable<T>Int32 实现来比较值。The Min<TSource>(IEnumerable<TSource>, Func<TSource,Int32>) method uses the Int32 implementation of IComparable<T> to compare values.

如果提供 selector,该函数将 source 的成员投影为数值类型(特别 Int32),则可以将此方法应用于任意值序列。You can apply this method to a sequence of arbitrary values if you provide a function, selector, that projects the members of source into a numeric type, specifically Int32.

在 Visual Basic 查询表达式语法中,Aggregate Into Min() 子句会转换为 Min调用。In Visual Basic query expression syntax, an Aggregate Into Min() clause translates to an invocation of Min.

See also

Min<TSource>(IEnumerable<TSource>, Func<TSource,Double>)

对序列中的每个元素调用转换函数,并返回最小的 Double 值。Invokes a transform function on each element of a sequence and returns the minimum Double value.

public:
generic <typename TSource>
[System::Runtime::CompilerServices::Extension]
 static double Min(System::Collections::Generic::IEnumerable<TSource> ^ source, Func<TSource, double> ^ selector);
public static double Min<TSource> (this System.Collections.Generic.IEnumerable<TSource> source, Func<TSource,double> selector);
static member Min : seq<'Source> * Func<'Source, double> -> double
<Extension()>
Public Function Min(Of TSource) (source As IEnumerable(Of TSource), selector As Func(Of TSource, Double)) As Double

Type Parameters

TSource

source 的元素类型。The type of the elements of source.

Parameters

source
IEnumerable<TSource>

要确定其最小值的值序列。A sequence of values to determine the minimum value of.

selector
Func<TSource,Double>

应用于每个元素的转换函数。A transform function to apply to each element.

Returns

Double

序列中的最小值。The minimum value in the sequence.

Exceptions

sourceselectornullsource or selector is null.

source 中不包含任何元素。source contains no elements.

Examples

下面的代码示例演示如何使用 Min<TSource>(IEnumerable<TSource>, Func<TSource,Int32>) 来确定投影值序列中的最小值。The following code example demonstrates how to use Min<TSource>(IEnumerable<TSource>, Func<TSource,Int32>) to determine the minimum value in a sequence of projected values.

Note

此代码示例使用此重载方法的重载,该重载与本主题介绍的特定重载不同。This code example uses an overload of this overloaded method that is different from the specific overload that this topic describes. 若要将此示例扩展到本主题,请更改 selector 函数体。To extend the example to this topic, change the body of the selector function.

class Pet
{
    public string Name { get; set; }
    public int Age { get; set; }
}

public static void MinEx4()
{
    Pet[] pets = { new Pet { Name="Barley", Age=8 },
                   new Pet { Name="Boots", Age=4 },
                   new Pet { Name="Whiskers", Age=1 } };

    int min = pets.Min(pet => pet.Age);

    Console.WriteLine("The youngest animal is age {0}.", min);
}

/*
 This code produces the following output:

 The youngest animal is age 1.
*/
Structure Pet
    Public Name As String
    Public Age As Integer
End Structure

Sub MinEx4()
    ' Create an array of Pet objects.
    Dim pets() As Pet = {New Pet With {.Name = "Barley", .Age = 8},
                     New Pet With {.Name = "Boots", .Age = 4},
                     New Pet With {.Name = "Whiskers", .Age = 1}}

    ' Find the youngest pet by passing a 
    ' lambda expression to the Min() method.
    Dim min As Integer = pets.Min(Function(pet) pet.Age)

    ' Display the result.
    Console.WriteLine($"The youngest pet is age {min}")
End Sub

' This code produces the following output:
'
' The youngest pet is age 1

Remarks

Min<TSource>(IEnumerable<TSource>, Func<TSource,Double>) 方法使用 IComparable<T>Double 实现来比较值。The Min<TSource>(IEnumerable<TSource>, Func<TSource,Double>) method uses the Double implementation of IComparable<T> to compare values.

如果提供 selector,该函数将 source 的成员投影为数值类型(特别 Double),则可以将此方法应用于任意值序列。You can apply this method to a sequence of arbitrary values if you provide a function, selector, that projects the members of source into a numeric type, specifically Double.

在 Visual Basic 查询表达式语法中,Aggregate Into Min() 子句会转换为 Min调用。In Visual Basic query expression syntax, an Aggregate Into Min() clause translates to an invocation of Min.

See also

Min<TSource>(IEnumerable<TSource>, Func<TSource,Decimal>)

对序列中的每个元素调用转换函数,并返回最小的 Decimal 值。Invokes a transform function on each element of a sequence and returns the minimum Decimal value.

public:
generic <typename TSource>
[System::Runtime::CompilerServices::Extension]
 static System::Decimal Min(System::Collections::Generic::IEnumerable<TSource> ^ source, Func<TSource, System::Decimal> ^ selector);
public static decimal Min<TSource> (this System.Collections.Generic.IEnumerable<TSource> source, Func<TSource,decimal> selector);
static member Min : seq<'Source> * Func<'Source, decimal> -> decimal
<Extension()>
Public Function Min(Of TSource) (source As IEnumerable(Of TSource), selector As Func(Of TSource, Decimal)) As Decimal

Type Parameters

TSource

source 的元素类型。The type of the elements of source.

Parameters

source
IEnumerable<TSource>

要确定其最小值的值序列。A sequence of values to determine the minimum value of.

selector
Func<TSource,Decimal>

应用于每个元素的转换函数。A transform function to apply to each element.

Returns

Decimal

序列中的最小值。The minimum value in the sequence.

Exceptions

sourceselectornullsource or selector is null.

source 中不包含任何元素。source contains no elements.

Examples

下面的代码示例演示如何使用 Min<TSource>(IEnumerable<TSource>, Func<TSource,Int32>) 来确定投影值序列中的最小值。The following code example demonstrates how to use Min<TSource>(IEnumerable<TSource>, Func<TSource,Int32>) to determine the minimum value in a sequence of projected values.

Note

此代码示例使用此重载方法的重载,该重载与本主题介绍的特定重载不同。This code example uses an overload of this overloaded method that is different from the specific overload that this topic describes. 若要将此示例扩展到本主题,请更改 selector 函数体。To extend the example to this topic, change the body of the selector function.

class Pet
{
    public string Name { get; set; }
    public int Age { get; set; }
}

public static void MinEx4()
{
    Pet[] pets = { new Pet { Name="Barley", Age=8 },
                   new Pet { Name="Boots", Age=4 },
                   new Pet { Name="Whiskers", Age=1 } };

    int min = pets.Min(pet => pet.Age);

    Console.WriteLine("The youngest animal is age {0}.", min);
}

/*
 This code produces the following output:

 The youngest animal is age 1.
*/
Structure Pet
    Public Name As String
    Public Age As Integer
End Structure

Sub MinEx4()
    ' Create an array of Pet objects.
    Dim pets() As Pet = {New Pet With {.Name = "Barley", .Age = 8},
                     New Pet With {.Name = "Boots", .Age = 4},
                     New Pet With {.Name = "Whiskers", .Age = 1}}

    ' Find the youngest pet by passing a 
    ' lambda expression to the Min() method.
    Dim min As Integer = pets.Min(Function(pet) pet.Age)

    ' Display the result.
    Console.WriteLine($"The youngest pet is age {min}")
End Sub

' This code produces the following output:
'
' The youngest pet is age 1

Remarks

Min<TSource>(IEnumerable<TSource>, Func<TSource,Decimal>) 方法使用 IComparable<T>Decimal 实现来比较值。The Min<TSource>(IEnumerable<TSource>, Func<TSource,Decimal>) method uses the Decimal implementation of IComparable<T> to compare values.

如果提供 selector,该函数将 source 的成员投影为数值类型(特别 Decimal),则可以将此方法应用于任意值序列。You can apply this method to a sequence of arbitrary values if you provide a function, selector, that projects the members of source into a numeric type, specifically Decimal.

在 Visual Basic 查询表达式语法中,Aggregate Into Min() 子句会转换为 Min调用。In Visual Basic query expression syntax, an Aggregate Into Min() clause translates to an invocation of Min.

See also

Min<TSource>(IEnumerable<TSource>)

返回泛型序列中的最小值。Returns the minimum value in a generic sequence.

public:
generic <typename TSource>
[System::Runtime::CompilerServices::Extension]
 static TSource Min(System::Collections::Generic::IEnumerable<TSource> ^ source);
public static TSource Min<TSource> (this System.Collections.Generic.IEnumerable<TSource> source);
static member Min : seq<'Source> -> 'Source
<Extension()>
Public Function Min(Of TSource) (source As IEnumerable(Of TSource)) As TSource

Type Parameters

TSource

source 的元素类型。The type of the elements of source.

Parameters

source
IEnumerable<TSource>

要确定其最小值的值序列。A sequence of values to determine the minimum value of.

Returns

TSource

序列中的最小值。The minimum value in the sequence.

Exceptions

sourcenullsource is null.

source 中没有对象实现 IComparableIComparable<T> 接口。No object in source implements the IComparable or IComparable<T> interface.

Examples

下面的代码示例演示如何使用 Min<TSource>(IEnumerable<TSource>) 确定 IComparable<T> 对象序列中的最小值。The following code example demonstrates how to use Min<TSource>(IEnumerable<TSource>) to determine the minimum value in a sequence of IComparable<T> objects.

/// <summary>
/// This class implements IComparable in order to
/// be able to compare different Pet objects.
/// </summary>
class Pet : IComparable<Pet>
{
    public string Name { get; set; }
    public int Age { get; set; }

    /// <summary>
    /// Compares this Pet's age to another Pet's age.
    /// </summary>
    /// <param name="other">The Pet to compare this Pet to.</param>
    /// <returns>-1 if this Pet's age is smaller,
    /// 0 if the Pets' ages are equal, or
    /// 1 if this Pet's age is greater.</returns>
    int IComparable<Pet>.CompareTo(Pet other)
    {
        if (other.Age > this.Age)
            return -1;
        else if (other.Age == this.Age)
            return 0;
        else
            return 1;
    }
}

public static void MinEx3()
{
    Pet[] pets = { new Pet { Name="Barley", Age=8 },
                   new Pet { Name="Boots", Age=4 },
                   new Pet { Name="Whiskers", Age=1 } };

    Pet min = pets.Min();

    Console.WriteLine(
        "The 'minimum' animal is {0}.",
        min.Name);
}

/*
 This code produces the following output:

 The 'minimum' animal is Whiskers.
*/
' This class implements IComparable 
' and has a custom 'CompareTo' implementation.
Class Pet
    Implements IComparable(Of Pet)

    Public Name As String
    Public Age As Integer

    ''' <summary>
    ''' Compares this Pet's age to another Pet's age.
    ''' </summary>
    ''' <param name="other">The Pet to compare this Pet to.</param>
    ''' <returns>-1 if this Pet's age is smaller,
    ''' 0 if the Pets' ages are equal,
    ''' or 1 if this Pet's age is greater.</returns>
    Function CompareTo(ByVal other As Pet) As Integer _
    Implements IComparable(Of Pet).CompareTo

        If (other.Age > Me.Age) Then
            Return -1
        ElseIf (other.Age = Me.Age) Then
            Return 0
        Else
            Return 1
        End If
    End Function
End Class

Sub MinEx3()
    ' Create an array of Pet objects.
    Dim pets() As Pet = {New Pet With {.Name = "Barley", .Age = 8},
                     New Pet With {.Name = "Boots", .Age = 4},
                     New Pet With {.Name = "Whiskers", .Age = 1}}

    ' Determine the "minimum" pet in the array,
    ' according to the custom CompareTo() implementation.
    Dim min As Pet = pets.Min()

    ' Display the result.
    Console.WriteLine($"The 'minimum' pet is {min.Name}")
End Sub

' This code produces the following output:
'
' The 'minimum' pet is Whiskers

Remarks

如果类型 TSource 实现 IComparable<T>,则此方法将使用该实现来比较值。If type TSource implements IComparable<T>, this method uses that implementation to compare values. 否则,如果类型 TSource 实现 IComparable,则该实现用于比较值。Otherwise, if type TSource implements IComparable, that implementation is used to compare values.

如果 TSource 是引用类型,并且源序列为空或仅包含 null的值,则此函数返回 nullIf TSource is a reference type and the source sequence is empty or contains only values that are null, this function returns null.

在 Visual Basic 查询表达式语法中,Aggregate Into Min() 子句会转换为 Min调用。In Visual Basic query expression syntax, an Aggregate Into Min() clause translates to an invocation of Min.

See also

Min<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Decimal>>)

对序列中的每个元素调用转换函数,并返回可以为 null 的最小的 Decimal 值。Invokes a transform function on each element of a sequence and returns the minimum nullable Decimal value.

public:
generic <typename TSource>
[System::Runtime::CompilerServices::Extension]
 static Nullable<System::Decimal> Min(System::Collections::Generic::IEnumerable<TSource> ^ source, Func<TSource, Nullable<System::Decimal>> ^ selector);
public static decimal? Min<TSource> (this System.Collections.Generic.IEnumerable<TSource> source, Func<TSource,Nullable<decimal>> selector);
static member Min : seq<'Source> * Func<'Source, Nullable<decimal>> -> Nullable<decimal>
<Extension()>
Public Function Min(Of TSource) (source As IEnumerable(Of TSource), selector As Func(Of TSource, Nullable(Of Decimal))) As Nullable(Of Decimal)

Type Parameters

TSource

source 的元素类型。The type of the elements of source.

Parameters

source
IEnumerable<TSource>

要确定其最小值的值序列。A sequence of values to determine the minimum value of.

selector
Func<TSource,Nullable<Decimal>>

应用于每个元素的转换函数。A transform function to apply to each element.

Returns

Nullable<Decimal>

与序列中的最小值相对应的值,该值的类型在 C# 中为 Nullable<Decimal>,在 Visual Basic 中为 Nullable(Of Decimal)The value of type Nullable<Decimal> in C# or Nullable(Of Decimal) in Visual Basic that corresponds to the minimum value in the sequence.

Exceptions

sourceselectornullsource or selector is null.

Examples

下面的代码示例演示如何使用 Min<TSource>(IEnumerable<TSource>, Func<TSource,Int32>) 来确定投影值序列中的最小值。The following code example demonstrates how to use Min<TSource>(IEnumerable<TSource>, Func<TSource,Int32>) to determine the minimum value in a sequence of projected values.

Note

此代码示例使用此重载方法的重载,该重载与本主题介绍的特定重载不同。This code example uses an overload of this overloaded method that is different from the specific overload that this topic describes. 若要将此示例扩展到本主题,请更改 selector 函数体。To extend the example to this topic, change the body of the selector function.

class Pet
{
    public string Name { get; set; }
    public int Age { get; set; }
}

public static void MinEx4()
{
    Pet[] pets = { new Pet { Name="Barley", Age=8 },
                   new Pet { Name="Boots", Age=4 },
                   new Pet { Name="Whiskers", Age=1 } };

    int min = pets.Min(pet => pet.Age);

    Console.WriteLine("The youngest animal is age {0}.", min);
}

/*
 This code produces the following output:

 The youngest animal is age 1.
*/
Structure Pet
    Public Name As String
    Public Age As Integer
End Structure

Sub MinEx4()
    ' Create an array of Pet objects.
    Dim pets() As Pet = {New Pet With {.Name = "Barley", .Age = 8},
                     New Pet With {.Name = "Boots", .Age = 4},
                     New Pet With {.Name = "Whiskers", .Age = 1}}

    ' Find the youngest pet by passing a 
    ' lambda expression to the Min() method.
    Dim min As Integer = pets.Min(Function(pet) pet.Age)

    ' Display the result.
    Console.WriteLine($"The youngest pet is age {min}")
End Sub

' This code produces the following output:
'
' The youngest pet is age 1

Remarks

Min<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Decimal>>) 方法使用 IComparable<T>Decimal 实现来比较值。The Min<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Decimal>>) method uses the Decimal implementation of IComparable<T> to compare values.

如果您提供了一个函数(selector),该函数将 source 的成员投影到一个数值类型中,特别是在C# Visual Basic 中 Nullable<Decimal>Nullable(Of Decimal),则可以将此方法应用于任意值序列。You can apply this method to a sequence of arbitrary values if you provide a function, selector, that projects the members of source into a numeric type, specifically Nullable<Decimal> in C# or Nullable(Of Decimal) in Visual Basic.

在 Visual Basic 查询表达式语法中,Aggregate Into Min() 子句会转换为 Min调用。In Visual Basic query expression syntax, an Aggregate Into Min() clause translates to an invocation of Min.

See also

Applies to