Enumerable.Min Метод
Определение
Возвращает минимальное значение, содержащееся в последовательности значений.Returns the minimum value in a sequence of values.
Перегрузки
Min(IEnumerable<Nullable<Int64>>) |
Возвращает минимальное значение в последовательности значений Int64 обнуляемого типа.Returns the minimum value in a sequence of nullable Int64 values. |
Min(IEnumerable<Nullable<Int32>>) |
Возвращает минимальное значение в последовательности значений 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>>) |
Возвращает минимальное значение в последовательности значений Single обнуляемого типа.Returns the minimum value in a sequence of nullable Single values. |
Min(IEnumerable<Nullable<Double>>) |
Возвращает минимальное значение в последовательности значений 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>>) |
Возвращает минимальное значение в последовательности значений 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>>) |
Вызывает функцию преобразования для каждого элемента последовательности и возвращает минимальное значение 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>>) |
Вызывает функцию преобразования для каждого элемента последовательности и возвращает минимальное значение 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>>) |
Вызывает функцию преобразования для каждого элемента последовательности и возвращает минимальное значение 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>>) |
Вызывает функцию преобразования для каждого элемента последовательности и возвращает минимальное значение 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>>) |
Вызывает функцию преобразования для каждого элемента последовательности и возвращает минимальное значение Decimal обнуляемого типа.Invokes a transform function on each element of a sequence and returns the minimum nullable Decimal value. |
Min(IEnumerable<Nullable<Int64>>)
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<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)
Параметры
- source
- IEnumerable<Nullable<Int64>>
Последовательность значений Int64 обнуляемого типа, для которой определяется минимальное значение.A sequence of nullable Int64 values to determine the minimum value of.
Возвращаемое значение
Значение типа Nullable<Int64>
в C# или Nullable(Of Int64)
в Visual Basic, соответствующее минимальному значению последовательности.A value of type Nullable<Int64>
in C# or Nullable(Of Int64)
in Visual Basic that corresponds to the minimum value in the sequence.
Исключения
source
имеет значение null
.source
is null
.
Комментарии
Min(IEnumerable<Nullable<Int64>>)Метод использует реализацию метода Int64 IComparable<T> для сравнения значений.The Min(IEnumerable<Nullable<Int64>>) method uses the Int64 implementation of IComparable<T> to compare values.
Если исходная последовательность пуста или содержит только значения, которые имеют значение null
, эта функция возвращает null
.If 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.
Применяется к
Min(IEnumerable<Nullable<Int32>>)
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<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)
Параметры
- source
- IEnumerable<Nullable<Int32>>
Последовательность значений Int32 обнуляемого типа, для которой определяется минимальное значение.A sequence of nullable Int32 values to determine the minimum value of.
Возвращаемое значение
Значение типа Nullable<Int32>
в C# или Nullable(Of Int32)
в Visual Basic, соответствующее минимальному значению последовательности.A value of type Nullable<Int32>
in C# or Nullable(Of Int32)
in Visual Basic that corresponds to the minimum value in the sequence.
Исключения
source
имеет значение null
.source
is null
.
Примеры
В следующем примере кода показано, как использовать 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
Комментарии
Min(IEnumerable<Nullable<Int32>>)Метод использует реализацию метода Int32 IComparable<T> для сравнения значений.The Min(IEnumerable<Nullable<Int32>>) method uses the Int32 implementation of IComparable<T> to compare values.
Если исходная последовательность пуста или содержит только значения, которые имеют значение null
, эта функция возвращает null
.If 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.
Применяется к
Min(IEnumerable<Single>)
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
Параметры
- source
- IEnumerable<Single>
Последовательность значений типа Single, для которой определяется минимальное значение.A sequence of Single values to determine the minimum value of.
Возвращаемое значение
Минимальное значение в последовательности.The minimum value in the sequence.
Исключения
source
имеет значение null
.source
is null
.
Последовательность source
не содержит элементов.source
contains no elements.
Комментарии
Min(IEnumerable<Single>)Метод использует реализацию метода Single IComparable<T> для сравнения значений.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.
Применяется к
Min(IEnumerable<Nullable<Single>>)
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<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)
Параметры
- source
- IEnumerable<Nullable<Single>>
Последовательность значений Single обнуляемого типа, для которой определяется минимальное значение.A sequence of nullable Single values to determine the minimum value of.
Возвращаемое значение
Значение типа Nullable<Single>
в C# или Nullable(Of Single)
в Visual Basic, соответствующее минимальному значению последовательности.A value of type Nullable<Single>
in C# or Nullable(Of Single)
in Visual Basic that corresponds to the minimum value in the sequence.
Исключения
source
имеет значение null
.source
is null
.
Комментарии
Min(IEnumerable<Nullable<Single>>)Метод использует реализацию метода Single IComparable<T> для сравнения значений.The Min(IEnumerable<Nullable<Single>>) method uses the Single implementation of IComparable<T> to compare values.
Если исходная последовательность пуста или содержит только значения, которые имеют значение null
, эта функция возвращает null
.If 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.
Применяется к
Min(IEnumerable<Nullable<Double>>)
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<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)
Параметры
- source
- IEnumerable<Nullable<Double>>
Последовательность значений Double обнуляемого типа, для которой определяется минимальное значение.A sequence of nullable Double values to determine the minimum value of.
Возвращаемое значение
Значение типа Nullable<Double>
в C# или Nullable(Of Double)
в Visual Basic, соответствующее минимальному значению последовательности.A value of type Nullable<Double>
in C# or Nullable(Of Double)
in Visual Basic that corresponds to the minimum value in the sequence.
Исключения
source
имеет значение null
.source
is null
.
Комментарии
Min(IEnumerable<Nullable<Double>>)Метод использует реализацию метода Double IComparable<T> для сравнения значений.The Min(IEnumerable<Nullable<Double>>) method uses the Double implementation of IComparable<T> to compare values.
Если исходная последовательность пуста или содержит только значения, которые имеют значение null
, эта функция возвращает null
.If 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.
Применяется к
Min(IEnumerable<Double>)
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
Параметры
- source
- IEnumerable<Double>
Последовательность значений типа Double, для которой определяется минимальное значение.A sequence of Double values to determine the minimum value of.
Возвращаемое значение
Минимальное значение в последовательности.The minimum value in the sequence.
Исключения
source
имеет значение null
.source
is null
.
Последовательность source
не содержит элементов.source
contains no elements.
Примеры
В следующем примере кода показано, как использовать 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
Комментарии
Min(IEnumerable<Double>)Метод использует реализацию метода Double IComparable<T> для сравнения значений.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.
Применяется к
Min(IEnumerable<Int64>)
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
Параметры
- source
- IEnumerable<Int64>
Последовательность значений типа Int64, для которой определяется минимальное значение.A sequence of Int64 values to determine the minimum value of.
Возвращаемое значение
Минимальное значение в последовательности.The minimum value in the sequence.
Исключения
source
имеет значение null
.source
is null
.
Последовательность source
не содержит элементов.source
contains no elements.
Комментарии
Min(IEnumerable<Int64>)Метод использует реализацию метода Int64 IComparable<T> для сравнения значений.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.
Применяется к
Min(IEnumerable<Int32>)
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
Параметры
- source
- IEnumerable<Int32>
Последовательность значений типа Int32, для которой определяется минимальное значение.A sequence of Int32 values to determine the minimum value of.
Возвращаемое значение
Минимальное значение в последовательности.The minimum value in the sequence.
Исключения
source
имеет значение null
.source
is null
.
Последовательность source
не содержит элементов.source
contains no elements.
Комментарии
Min(IEnumerable<Int32>)Метод использует реализацию метода Int32 IComparable<T> для сравнения значений.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.
Применяется к
Min(IEnumerable<Nullable<Decimal>>)
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<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)
Параметры
- source
- IEnumerable<Nullable<Decimal>>
Последовательность значений Decimal обнуляемого типа, для которой определяется минимальное значение.A sequence of nullable Decimal values to determine the minimum value of.
Возвращаемое значение
Значение типа Nullable<Decimal>
в C# или Nullable(Of Decimal)
в Visual Basic, соответствующее минимальному значению последовательности.A value of type Nullable<Decimal>
in C# or Nullable(Of Decimal)
in Visual Basic that corresponds to the minimum value in the sequence.
Исключения
source
имеет значение null
.source
is null
.
Комментарии
Min(IEnumerable<Nullable<Decimal>>)Метод использует реализацию метода Decimal IComparable<T> для сравнения значений.The Min(IEnumerable<Nullable<Decimal>>) method uses the Decimal implementation of IComparable<T> to compare values.
Если исходная последовательность пуста или содержит только значения, которые имеют значение null
, эта функция возвращает null
.If 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.
Применяется к
Min(IEnumerable<Decimal>)
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
Параметры
- source
- IEnumerable<Decimal>
Последовательность значений типа Decimal, для которой определяется минимальное значение.A sequence of Decimal values to determine the minimum value of.
Возвращаемое значение
Минимальное значение в последовательности.The minimum value in the sequence.
Исключения
source
имеет значение null
.source
is null
.
Последовательность source
не содержит элементов.source
contains no elements.
Комментарии
Min(IEnumerable<Decimal>)Метод использует реализацию метода Decimal IComparable<T> для сравнения значений.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.
Применяется к
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);
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
Параметры типа
- TSource
Тип элементов source
.The type of the elements of source
.
- TResult
Тип значения, возвращаемого функцией selector
.The type of the value returned by selector
.
Параметры
- 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.
Возвращаемое значение
- TResult
Минимальное значение в последовательности.The minimum value in the sequence.
Исключения
Параметр source
или selector
имеет значение null
.source
or selector
is null
.
Примеры
В следующем примере кода показано, как использовать 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.
Примечание
В этом примере кода используется перегруженная версия данного метода, отличная от его перегруженной версии, описанной в настоящем разделе.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
Комментарии
Если тип 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.
Применяется к
Min<TSource>(IEnumerable<TSource>, Func<TSource,Single>)
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
Параметры типа
- TSource
Тип элементов source
.The type of the elements of source
.
Параметры
- source
- IEnumerable<TSource>
Последовательность значений, для которой определяется минимальное значение.A sequence of values to determine the minimum value of.
Функция преобразования, применяемая к каждому элементу.A transform function to apply to each element.
Возвращаемое значение
Минимальное значение в последовательности.The minimum value in the sequence.
Исключения
Параметр source
или selector
имеет значение null
.source
or selector
is null
.
Последовательность source
не содержит элементов.source
contains no elements.
Примеры
В следующем примере кода показано, как использовать 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.
Примечание
В этом примере кода используется перегруженная версия данного метода, отличная от его перегруженной версии, описанной в настоящем разделе.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
Комментарии
Min<TSource>(IEnumerable<TSource>, Func<TSource,Single>)Метод использует реализацию метода Single IComparable<T> для сравнения значений.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.
Применяется к
Min<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Single>>)
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,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)
Параметры типа
- TSource
Тип элементов source
.The type of the elements of source
.
Параметры
- source
- IEnumerable<TSource>
Последовательность значений, для которой определяется минимальное значение.A sequence of values to determine the minimum value of.
Функция преобразования, применяемая к каждому элементу.A transform function to apply to each element.
Возвращаемое значение
Значение типа Nullable<Single>
в C# или Nullable(Of Single)
в Visual Basic, соответствующее минимальному значению последовательности.The value of type Nullable<Single>
in C# or Nullable(Of Single)
in Visual Basic that corresponds to the minimum value in the sequence.
Исключения
Параметр source
или selector
имеет значение null
.source
or selector
is null
.
Примеры
В следующем примере кода показано, как использовать 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.
Примечание
В этом примере кода используется перегруженная версия данного метода, отличная от его перегруженной версии, описанной в настоящем разделе.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
Комментарии
Min<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Single>>)Метод использует реализацию метода Single IComparable<T> для сравнения значений.The Min<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Single>>) method uses the Single implementation of IComparable<T> to compare values.
Этот метод можно применить к последовательности произвольных значений, если вы предоставляете функцию, selector
которая проецирует элементы source
в числовой тип, в частности Nullable<Single>
в C# или Nullable(Of Single)
в Visual Basic.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.
Применяется к
Min<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Int64>>)
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,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)
Параметры типа
- TSource
Тип элементов source
.The type of the elements of source
.
Параметры
- source
- IEnumerable<TSource>
Последовательность значений, для которой определяется минимальное значение.A sequence of values to determine the minimum value of.
Функция преобразования, применяемая к каждому элементу.A transform function to apply to each element.
Возвращаемое значение
Значение типа Nullable<Int64>
в C# или Nullable(Of Int64)
в Visual Basic, соответствующее минимальному значению последовательности.The value of type Nullable<Int64>
in C# or Nullable(Of Int64)
in Visual Basic that corresponds to the minimum value in the sequence.
Исключения
Параметр source
или selector
имеет значение null
.source
or selector
is null
.
Примеры
В следующем примере кода показано, как использовать 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.
Примечание
В этом примере кода используется перегруженная версия данного метода, отличная от его перегруженной версии, описанной в настоящем разделе.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
Комментарии
Min<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Int64>>)Метод использует реализацию метода Int64 IComparable<T> для сравнения значений.The Min<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Int64>>) method uses the Int64 implementation of IComparable<T> to compare values.
Этот метод можно применить к последовательности произвольных значений, если вы предоставляете функцию, selector
которая проецирует элементы source
в числовой тип, в частности Nullable<Int64>
в C# или Nullable(Of Int64)
в Visual Basic.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.
Применяется к
Min<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Int32>>)
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,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)
Параметры типа
- TSource
Тип элементов source
.The type of the elements of source
.
Параметры
- source
- IEnumerable<TSource>
Последовательность значений, для которой определяется минимальное значение.A sequence of values to determine the minimum value of.
Функция преобразования, применяемая к каждому элементу.A transform function to apply to each element.
Возвращаемое значение
Значение типа Nullable<Int32>
в C# или Nullable(Of Int32)
в Visual Basic, соответствующее минимальному значению последовательности.The value of type Nullable<Int32>
in C# or Nullable(Of Int32)
in Visual Basic that corresponds to the minimum value in the sequence.
Исключения
Параметр source
или selector
имеет значение null
.source
or selector
is null
.
Примеры
В следующем примере кода показано, как использовать 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.
Примечание
В этом примере кода используется перегруженная версия данного метода, отличная от его перегруженной версии, описанной в настоящем разделе.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
Комментарии
Min<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Int32>>)Метод использует реализацию метода Int32 IComparable<T> для сравнения значений.The Min<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Int32>>) method uses the Int32 implementation of IComparable<T> to compare values.
Этот метод можно применить к последовательности произвольных значений, если вы предоставляете функцию, selector
которая проецирует элементы источника в числовой тип, в частности Nullable<Int32>
в C# или Nullable(Of Int32)
в Visual Basic.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.
Применяется к
Min<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Double>>)
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,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)
Параметры типа
- TSource
Тип элементов source
.The type of the elements of source
.
Параметры
- source
- IEnumerable<TSource>
Последовательность значений, для которой определяется минимальное значение.A sequence of values to determine the minimum value of.
Функция преобразования, применяемая к каждому элементу.A transform function to apply to each element.
Возвращаемое значение
Значение типа Nullable<Double>
в C# или Nullable(Of Double)
в Visual Basic, соответствующее минимальному значению последовательности.The value of type Nullable<Double>
in C# or Nullable(Of Double)
in Visual Basic that corresponds to the minimum value in the sequence.
Исключения
Параметр source
или selector
имеет значение null
.source
or selector
is null
.
Примеры
В следующем примере кода показано, как использовать 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.
Примечание
В этом примере кода используется перегруженная версия данного метода, отличная от его перегруженной версии, описанной в настоящем разделе.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
Комментарии
Min<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Double>>)Метод использует реализацию метода Double IComparable<T> для сравнения значений.The Min<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Double>>) method uses the Double implementation of IComparable<T> to compare values.
Этот метод можно применить к последовательности произвольных значений, если вы предоставляете функцию, selector
которая проецирует элементы source
в числовой тип, в частности Nullable<Double>
в C# или Nullable(Of Double)
в Visual Basic.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.
Применяется к
Min<TSource>(IEnumerable<TSource>, Func<TSource,Int64>)
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
Параметры типа
- TSource
Тип элементов source
.The type of the elements of source
.
Параметры
- source
- IEnumerable<TSource>
Последовательность значений, для которой определяется минимальное значение.A sequence of values to determine the minimum value of.
Функция преобразования, применяемая к каждому элементу.A transform function to apply to each element.
Возвращаемое значение
Минимальное значение в последовательности.The minimum value in the sequence.
Исключения
Параметр source
или selector
имеет значение null
.source
or selector
is null
.
Последовательность source
не содержит элементов.source
contains no elements.
Примеры
В следующем примере кода показано, как использовать 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.
Примечание
В этом примере кода используется перегруженная версия данного метода, отличная от его перегруженной версии, описанной в настоящем разделе.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
Комментарии
Min<TSource>(IEnumerable<TSource>, Func<TSource,Int64>)Метод использует реализацию метода Int64 IComparable<T> для сравнения значений.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.
Применяется к
Min<TSource>(IEnumerable<TSource>, Func<TSource,Int32>)
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
Параметры типа
- TSource
Тип элементов source
.The type of the elements of source
.
Параметры
- source
- IEnumerable<TSource>
Последовательность значений, для которой определяется минимальное значение.A sequence of values to determine the minimum value of.
Функция преобразования, применяемая к каждому элементу.A transform function to apply to each element.
Возвращаемое значение
Минимальное значение в последовательности.The minimum value in the sequence.
Исключения
Параметр source
или selector
имеет значение null
.source
or selector
is null
.
Последовательность source
не содержит элементов.source
contains no elements.
Примеры
В следующем примере кода показано, как использовать 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
Комментарии
Min<TSource>(IEnumerable<TSource>, Func<TSource,Int32>)Метод использует реализацию метода Int32 IComparable<T> для сравнения значений.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.
Применяется к
Min<TSource>(IEnumerable<TSource>, Func<TSource,Double>)
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
Параметры типа
- TSource
Тип элементов source
.The type of the elements of source
.
Параметры
- source
- IEnumerable<TSource>
Последовательность значений, для которой определяется минимальное значение.A sequence of values to determine the minimum value of.
Функция преобразования, применяемая к каждому элементу.A transform function to apply to each element.
Возвращаемое значение
Минимальное значение в последовательности.The minimum value in the sequence.
Исключения
Параметр source
или selector
имеет значение null
.source
or selector
is null
.
Последовательность source
не содержит элементов.source
contains no elements.
Примеры
В следующем примере кода показано, как использовать 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.
Примечание
В этом примере кода используется перегруженная версия данного метода, отличная от его перегруженной версии, описанной в настоящем разделе.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
Комментарии
Min<TSource>(IEnumerable<TSource>, Func<TSource,Double>)Метод использует реализацию метода Double IComparable<T> для сравнения значений.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.
Применяется к
Min<TSource>(IEnumerable<TSource>, Func<TSource,Decimal>)
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
Параметры типа
- TSource
Тип элементов source
.The type of the elements of source
.
Параметры
- source
- IEnumerable<TSource>
Последовательность значений, для которой определяется минимальное значение.A sequence of values to determine the minimum value of.
Функция преобразования, применяемая к каждому элементу.A transform function to apply to each element.
Возвращаемое значение
Минимальное значение в последовательности.The minimum value in the sequence.
Исключения
Параметр source
или selector
имеет значение null
.source
or selector
is null
.
Последовательность source
не содержит элементов.source
contains no elements.
Примеры
В следующем примере кода показано, как использовать 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.
Примечание
В этом примере кода используется перегруженная версия данного метода, отличная от его перегруженной версии, описанной в настоящем разделе.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
Комментарии
Min<TSource>(IEnumerable<TSource>, Func<TSource,Decimal>)Метод использует реализацию метода Decimal IComparable<T> для сравнения значений.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.
Применяется к
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);
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
Параметры типа
- TSource
Тип элементов source
.The type of the elements of source
.
Параметры
- source
- IEnumerable<TSource>
Последовательность значений, для которой определяется минимальное значение.A sequence of values to determine the minimum value of.
Возвращаемое значение
- TSource
Минимальное значение в последовательности.The minimum value in the sequence.
Исключения
source
имеет значение null
.source
is null
.
Ни один объект в source
не реализует интерфейс IComparable или IComparable<T>.No object in source
implements the IComparable or IComparable<T> interface.
Примеры
В следующем примере кода показано, как использовать 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
Комментарии
Если тип 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
, эта функция возвращает null
.If 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.
Применяется к
Min<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Decimal>>)
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,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)
Параметры типа
- TSource
Тип элементов source
.The type of the elements of source
.
Параметры
- source
- IEnumerable<TSource>
Последовательность значений, для которой определяется минимальное значение.A sequence of values to determine the minimum value of.
Функция преобразования, применяемая к каждому элементу.A transform function to apply to each element.
Возвращаемое значение
Значение типа Nullable<Decimal>
в C# или Nullable(Of Decimal)
в Visual Basic, соответствующее минимальному значению последовательности.The value of type Nullable<Decimal>
in C# or Nullable(Of Decimal)
in Visual Basic that corresponds to the minimum value in the sequence.
Исключения
Параметр source
или selector
имеет значение null
.source
or selector
is null
.
Примеры
В следующем примере кода показано, как использовать 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.
Примечание
В этом примере кода используется перегруженная версия данного метода, отличная от его перегруженной версии, описанной в настоящем разделе.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
Комментарии
Min<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Decimal>>)Метод использует реализацию метода Decimal IComparable<T> для сравнения значений.The Min<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Decimal>>) method uses the Decimal implementation of IComparable<T> to compare values.
Этот метод можно применить к последовательности произвольных значений, если вы предоставляете функцию, selector
которая проецирует элементы source
в числовой тип, в частности Nullable<Decimal>
в C# или Nullable(Of Decimal)
в Visual Basic.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.