Enumerable.Min 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
回傳一連串值中的最小值。
多載
Min(IEnumerable<Single>)
- 來源:
- Min.cs
- 來源:
- Min.cs
- 來源:
- Min.cs
- 來源:
- Min.cs
- 來源:
- Min.cs
回傳一連 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 的值用以決定最小值。
傳回
序列中的最小值。
例外狀況
source 是 null。
source 不含任何元素。
備註
此 Min(IEnumerable<Single>) 方法利用 Single 的 IComparable<T> 實作來比較數值。
在Visual Basic查詢表達式語法中,Aggregate Into Min()子句可轉譯為Min的呼叫。
另請參閱
適用於
Min(IEnumerable<Nullable<Single>>)
- 來源:
- Min.cs
- 來源:
- Min.cs
- 來源:
- Min.cs
- 來源:
- Min.cs
- 來源:
- Min.cs
回傳一串可 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 空值用以確定最小值。
傳回
對應於序列中最小值的值。
例外狀況
source 是 null。
備註
此 Min(IEnumerable<Nullable<Single>>) 方法利用 Single 的 IComparable<T> 實作來比較數值。
若來源序列為空或僅包含 的 null值,該函數會回傳 null。
在Visual Basic查詢表達式語法中,Aggregate Into Min()子句可轉譯為Min的呼叫。
另請參閱
適用於
Min(IEnumerable<Nullable<Int32>>)
- 來源:
- Min.cs
- 來源:
- Min.cs
- 來源:
- Min.cs
- 來源:
- Min.cs
- 來源:
- Min.cs
回傳一串可 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 空值用以確定最小值。
傳回
對應於序列中最小值的值。
例外狀況
source 是 null。
範例
以下程式碼範例示範如何用 Min(IEnumerable<Nullable<Int32>>) 來決定序列中的最小值。
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> 實作來比較數值。
若來源序列為空或僅包含 的 null值,該函數會回傳 null。
在Visual Basic查詢表達式語法中,Aggregate Into Min()子句可轉譯為Min的呼叫。
另請參閱
適用於
Min(IEnumerable<Nullable<Double>>)
- 來源:
- Min.cs
- 來源:
- Min.cs
- 來源:
- Min.cs
- 來源:
- Min.cs
- 來源:
- Min.cs
回傳一串可 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 空值用以確定最小值。
傳回
對應於序列中最小值的值。
例外狀況
source 是 null。
備註
此 Min(IEnumerable<Nullable<Double>>) 方法利用 Double 的 IComparable<T> 實作來比較數值。
若來源序列為空或僅包含 的 null值,該函數會回傳 null。
在Visual Basic查詢表達式語法中,Aggregate Into Min()子句可轉譯為Min的呼叫。
另請參閱
適用於
Min(IEnumerable<Nullable<Int64>>)
- 來源:
- Min.cs
- 來源:
- Min.cs
- 來源:
- Min.cs
- 來源:
- Min.cs
- 來源:
- Min.cs
回傳一串可 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 空值用以確定最小值。
傳回
對應於序列中最小值的值。
例外狀況
source 是 null。
備註
此 Min(IEnumerable<Nullable<Int64>>) 方法利用 Int64 的 IComparable<T> 實作來比較數值。
若來源序列為空或僅包含 的 null值,該函數會回傳 null。
在Visual Basic查詢表達式語法中,Aggregate Into Min()子句可轉譯為Min的呼叫。
另請參閱
適用於
Min(IEnumerable<Int64>)
- 來源:
- Min.cs
- 來源:
- Min.cs
- 來源:
- Min.cs
- 來源:
- Min.cs
- 來源:
- Min.cs
回傳一連 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 的值用以決定最小值。
傳回
序列中的最小值。
例外狀況
source 是 null。
source 不含任何元素。
備註
此 Min(IEnumerable<Int64>) 方法利用 Int64 的 IComparable<T> 實作來比較數值。
在Visual Basic查詢表達式語法中,Aggregate Into Min()子句可轉譯為Min的呼叫。
另請參閱
適用於
Min(IEnumerable<Int32>)
- 來源:
- Min.cs
- 來源:
- Min.cs
- 來源:
- Min.cs
- 來源:
- Min.cs
- 來源:
- Min.cs
回傳一連 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 的值用以決定最小值。
傳回
序列中的最小值。
例外狀況
source 是 null。
source 不含任何元素。
備註
此 Min(IEnumerable<Int32>) 方法利用 Int32 的 IComparable<T> 實作來比較數值。
在Visual Basic查詢表達式語法中,Aggregate Into Min()子句可轉譯為Min的呼叫。
另請參閱
適用於
Min(IEnumerable<Double>)
- 來源:
- Min.cs
- 來源:
- Min.cs
- 來源:
- Min.cs
- 來源:
- Min.cs
- 來源:
- Min.cs
回傳一連 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 的值用以決定最小值。
傳回
序列中的最小值。
例外狀況
source 是 null。
source 不含任何元素。
範例
以下程式碼範例示範如何用 Min(IEnumerable<Double>) 來決定序列中的最小值。
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> 實作來比較數值。
在Visual Basic查詢表達式語法中,Aggregate Into Min()子句可轉譯為Min的呼叫。
另請參閱
適用於
Min(IEnumerable<Decimal>)
- 來源:
- Min.cs
- 來源:
- Min.cs
- 來源:
- Min.cs
- 來源:
- Min.cs
- 來源:
- Min.cs
回傳一連 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 的值用以決定最小值。
傳回
序列中的最小值。
例外狀況
source 是 null。
source 不含任何元素。
備註
此 Min(IEnumerable<Decimal>) 方法利用 Decimal 的 IComparable<T> 實作來比較數值。
在Visual Basic查詢表達式語法中,Aggregate Into Min()子句可轉譯為Min的呼叫。
另請參閱
適用於
Min(IEnumerable<Nullable<Decimal>>)
- 來源:
- Min.cs
- 來源:
- Min.cs
- 來源:
- Min.cs
- 來源:
- Min.cs
- 來源:
- Min.cs
回傳一串可 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 空值用以確定最小值。
傳回
對應於序列中最小值的值。
例外狀況
source 是 null。
備註
此 Min(IEnumerable<Nullable<Decimal>>) 方法利用 Decimal 的 IComparable<T> 實作來比較數值。
若來源序列為空或僅包含 的 null值,該函數會回傳 null。
在Visual Basic查詢表達式語法中,Aggregate Into Min()子句可轉譯為Min的呼叫。
另請參閱
適用於
Min<TSource,TResult>(IEnumerable<TSource>, Func<TSource,TResult>)
- 來源:
- Min.cs
- 來源:
- Min.cs
- 來源:
- Min.cs
- 來源:
- Min.cs
- 來源:
- Min.cs
在泛型序列的每個專案上叫用轉換函式,並傳回產生的最小值。
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的類型。
- TResult
由 返回 selector的值類型。
參數
- source
- IEnumerable<TSource>
一連串的值用以決定最小值。
- selector
- Func<TSource,TResult>
一個轉換函數,可以套用到每個元素。
傳回
序列中的最小值。
例外狀況
source 或 selector 為 null。
範例
以下程式碼範例示範如何用 Min<TSource>(IEnumerable<TSource>, Func<TSource,Int32>) 來確定投影值序列中的最小值。
Note
這個程式碼範例使用的方法的超載,與本文描述的具體超載不同。 若要將範例延伸到本文描述的過載,請改變函數的主體 selector 。
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>作 ,此方法利用該實作來比較值。 否則,若型別 TResult 實 IComparable作 ,則該實作用於比較值。
在Visual Basic查詢表達式語法中,Aggregate Into Min()子句可轉譯為Min的呼叫。
另請參閱
適用於
Min<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Int32>>)
- 來源:
- Min.cs
- 來源:
- Min.cs
- 來源:
- Min.cs
- 來源:
- Min.cs
- 來源:
- Min.cs
在序列的每個專案上叫用轉換函式,並傳回可為 null 的最小值 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的類型。
參數
- source
- IEnumerable<TSource>
一連串的值用以決定最小值。
傳回
對應於序列中最小值的值。
例外狀況
source 或 selector 為 null。
範例
以下程式碼範例示範如何用 Min<TSource>(IEnumerable<TSource>, Func<TSource,Int32>) 來確定投影值序列中的最小值。
Note
這個程式碼範例使用的方法的超載,與本文描述的具體超載不同。 若要將範例延伸到本文描述的過載,請改變函數的主體 selector 。
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> 實作來比較數值。
如果你提供一個函式,selector,將原始碼的成員投影成數值型別,具體來說,C# 中的 Nullable<Int32> 或 Visual Basic 中的 Nullable(Of Int32),你可以將此方法應用於任意值序列。
在Visual Basic查詢表達式語法中,Aggregate Into Min()子句可轉譯為Min的呼叫。
另請參閱
適用於
Min<TSource>(IEnumerable<TSource>, Func<TSource,Single>)
- 來源:
- Min.cs
- 來源:
- Min.cs
- 來源:
- Min.cs
- 來源:
- Min.cs
- 來源:
- Min.cs
在序列的每個元素上叫用轉換函式,並傳回最小值 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的類型。
參數
- source
- IEnumerable<TSource>
一連串的值用以決定最小值。
傳回
序列中的最小值。
例外狀況
source 或 selector 為 null。
source 不含任何元素。
範例
以下程式碼範例示範如何用 Min<TSource>(IEnumerable<TSource>, Func<TSource,Int32>) 來確定投影值序列中的最小值。
Note
這個程式碼範例使用的方法的超載,與本文描述的具體超載不同。 若要將範例延伸到本文描述的過載,請改變函數的主體 selector 。
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> 實作來比較數值。
如果你提供一個函數 selector,將 的 source 成員投影成一個數值型別,具體來說 Single,你可以將此方法應用於任意值序列。
在Visual Basic查詢表達式語法中,Aggregate Into Min()子句可轉譯為Min的呼叫。
另請參閱
適用於
Min<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Single>>)
- 來源:
- Min.cs
- 來源:
- Min.cs
- 來源:
- Min.cs
- 來源:
- Min.cs
- 來源:
- Min.cs
在序列的每個專案上叫用轉換函式,並傳回可為 null 的最小值 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的類型。
參數
- source
- IEnumerable<TSource>
一連串的值用以決定最小值。
傳回
對應於序列中最小值的值。
例外狀況
source 或 selector 為 null。
範例
以下程式碼範例示範如何用 Min<TSource>(IEnumerable<TSource>, Func<TSource,Int32>) 來確定投影值序列中的最小值。
Note
這個程式碼範例使用的方法的超載,與本文描述的具體超載不同。 若要將範例延伸到本文描述的過載,請改變函數的主體 selector 。
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> 實作來比較數值。
如果你提供一個函數 selector,將 source 的成員投影成數值型態,例如在 C# 中的 Nullable<Single> 或在 Visual Basic 中的 Nullable(Of Single),就可以將此方法應用於任意值序列。
在Visual Basic查詢表達式語法中,Aggregate Into Min()子句可轉譯為Min的呼叫。
另請參閱
適用於
Min<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Int64>>)
- 來源:
- Min.cs
- 來源:
- Min.cs
- 來源:
- Min.cs
- 來源:
- Min.cs
- 來源:
- Min.cs
在序列的每個專案上叫用轉換函式,並傳回可為 null 的最小值 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的類型。
參數
- source
- IEnumerable<TSource>
一連串的值用以決定最小值。
傳回
對應於序列中最小值的值。
例外狀況
source 或 selector 為 null。
範例
以下程式碼範例示範如何用 Min<TSource>(IEnumerable<TSource>, Func<TSource,Int32>) 來確定投影值序列中的最小值。
Note
這個程式碼範例使用的方法的超載,與本文描述的具體超載不同。 若要將範例延伸到本文描述的過載,請改變函數的主體 selector 。
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> 實作來比較數值。
如果你提供一個函數 selector,將 source 的成員投影成數值型態,例如在 C# 中的 Nullable<Int64> 或在 Visual Basic 中的 Nullable(Of Int64),就可以將此方法應用於任意值序列。
在Visual Basic查詢表達式語法中,Aggregate Into Min()子句可轉譯為Min的呼叫。
另請參閱
適用於
Min<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Double>>)
- 來源:
- Min.cs
- 來源:
- Min.cs
- 來源:
- Min.cs
- 來源:
- Min.cs
- 來源:
- Min.cs
在序列的每個專案上叫用轉換函式,並傳回可為 null 的最小值 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的類型。
參數
- source
- IEnumerable<TSource>
一連串的值用以決定最小值。
傳回
對應於序列中最小值的值。
例外狀況
source 或 selector 為 null。
範例
以下程式碼範例示範如何用 Min<TSource>(IEnumerable<TSource>, Func<TSource,Int32>) 來確定投影值序列中的最小值。
Note
這個程式碼範例使用的方法的超載,與本文描述的具體超載不同。 若要將範例延伸到本文描述的過載,請改變函數的主體 selector 。
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> 實作來比較數值。
如果你提供一個函數 selector,將 source 的成員投影成數值型態,例如在 C# 中的 Nullable<Double> 或在 Visual Basic 中的 Nullable(Of Double),就可以將此方法應用於任意值序列。
在Visual Basic查詢表達式語法中,Aggregate Into Min()子句可轉譯為Min的呼叫。
另請參閱
適用於
Min<TSource>(IEnumerable<TSource>, Func<TSource,Decimal>)
- 來源:
- Min.cs
- 來源:
- Min.cs
- 來源:
- Min.cs
- 來源:
- Min.cs
- 來源:
- Min.cs
在序列的每個元素上叫用轉換函式,並傳回最小值 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的類型。
參數
- source
- IEnumerable<TSource>
一連串的值用以決定最小值。
傳回
序列中的最小值。
例外狀況
source 或 selector 為 null。
source 不含任何元素。
範例
以下程式碼範例示範如何用 Min<TSource>(IEnumerable<TSource>, Func<TSource,Int32>) 來確定投影值序列中的最小值。
Note
這個程式碼範例使用的方法的超載,與本文描述的具體超載不同。 若要將範例延伸到本文描述的過載,請改變函數的主體 selector 。
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> 實作來比較數值。
如果你提供一個函數 selector,將 的 source 成員投影成一個數值型別,具體來說 Decimal,你可以將此方法應用於任意值序列。
在Visual Basic查詢表達式語法中,Aggregate Into Min()子句可轉譯為Min的呼叫。
另請參閱
適用於
Min<TSource>(IEnumerable<TSource>, Func<TSource,Int64>)
- 來源:
- Min.cs
- 來源:
- Min.cs
- 來源:
- Min.cs
- 來源:
- Min.cs
- 來源:
- Min.cs
在序列的每個元素上叫用轉換函式,並傳回最小值 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的類型。
參數
- source
- IEnumerable<TSource>
一連串的值用以決定最小值。
傳回
序列中的最小值。
例外狀況
source 或 selector 為 null。
source 不含任何元素。
範例
以下程式碼範例示範如何用 Min<TSource>(IEnumerable<TSource>, Func<TSource,Int32>) 來確定投影值序列中的最小值。
Note
這個程式碼範例使用的方法的超載,與本文描述的具體超載不同。 若要將範例延伸到本文描述的過載,請改變函數的主體 selector 。
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> 實作來比較數值。
如果你提供一個函數 selector,將 的 source 成員投影成一個數值型別,具體來說 Int64,你可以將此方法應用於任意值序列。
在Visual Basic查詢表達式語法中,Aggregate Into Min()子句可轉譯為Min的呼叫。
另請參閱
適用於
Min<TSource>(IEnumerable<TSource>, Func<TSource,Int32>)
- 來源:
- Min.cs
- 來源:
- Min.cs
- 來源:
- Min.cs
- 來源:
- Min.cs
- 來源:
- Min.cs
在序列的每個元素上叫用轉換函式,並傳回最小值 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的類型。
參數
- source
- IEnumerable<TSource>
一連串的值用以決定最小值。
傳回
序列中的最小值。
例外狀況
source 或 selector 為 null。
source 不含任何元素。
範例
以下程式碼範例示範如何用 Min<TSource>(IEnumerable<TSource>, Func<TSource,Int32>) 來確定投影值序列中的最小值。
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> 實作來比較數值。
如果你提供一個函數 selector,將 的 source 成員投影成一個數值型別,具體來說 Int32,你可以將此方法應用於任意值序列。
在Visual Basic查詢表達式語法中,Aggregate Into Min()子句可轉譯為Min的呼叫。
另請參閱
適用於
Min<TSource>(IEnumerable<TSource>, Func<TSource,Double>)
- 來源:
- Min.cs
- 來源:
- Min.cs
- 來源:
- Min.cs
- 來源:
- Min.cs
- 來源:
- Min.cs
在序列的每個元素上叫用轉換函式,並傳回最小值 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的類型。
參數
- source
- IEnumerable<TSource>
一連串的值用以決定最小值。
傳回
序列中的最小值。
例外狀況
source 或 selector 為 null。
source 不含任何元素。
範例
以下程式碼範例示範如何用 Min<TSource>(IEnumerable<TSource>, Func<TSource,Int32>) 來確定投影值序列中的最小值。
Note
這個程式碼範例使用的方法的超載,與本文描述的具體超載不同。 若要將範例延伸到本文描述的過載,請改變函數的主體 selector 。
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> 實作來比較數值。
如果你提供一個函數 selector,將 的 source 成員投影成一個數值型別,具體來說 Double,你可以將此方法應用於任意值序列。
在Visual Basic查詢表達式語法中,Aggregate Into Min()子句可轉譯為Min的呼叫。
另請參閱
適用於
Min<TSource>(IEnumerable<TSource>, IComparer<TSource>)
- 來源:
- Min.cs
- 來源:
- Min.cs
- 來源:
- Min.cs
- 來源:
- Min.cs
- 來源:
- Min.cs
傳回泛型序列中的最小值。
public:
generic <typename TSource>
[System::Runtime::CompilerServices::Extension]
static TSource Min(System::Collections::Generic::IEnumerable<TSource> ^ source, System::Collections::Generic::IComparer<TSource> ^ comparer);
public static TSource? Min<TSource>(this System.Collections.Generic.IEnumerable<TSource> source, System.Collections.Generic.IComparer<TSource>? comparer);
static member Min : seq<'Source> * System.Collections.Generic.IComparer<'Source> -> 'Source
<Extension()>
Public Function Min(Of TSource) (source As IEnumerable(Of TSource), comparer As IComparer(Of TSource)) As TSource
類型參數
- TSource
元素 source的類型。
參數
- source
- IEnumerable<TSource>
一連串的值用以決定最小值。
- comparer
- IComparer<TSource>
比較 IComparer<T> 價值。
傳回
序列中的最小值。
例外狀況
source 是 null。
沒有任何 source 物件實 IComparable 作 OR IComparable<T> 介面。
備註
若型別 TSource 實 IComparable<T>作 ,該 Max<TSource>(IEnumerable<TSource>) 方法會利用該實作來比較值。 否則,若型別 TSource 實 IComparable作 ,則該實作用於比較值。
若 TSource 是參考型別且來源序列為空或僅包含 , null此方法會回傳 null。
在Visual Basic查詢表達式語法中,Aggregate Into Min()子句可轉譯為Min的呼叫。
適用於
Min<TSource>(IEnumerable<TSource>)
- 來源:
- Min.cs
- 來源:
- Min.cs
- 來源:
- Min.cs
- 來源:
- Min.cs
- 來源:
- Min.cs
傳回泛型序列中的最小值。
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的類型。
參數
- source
- IEnumerable<TSource>
一連串的值用以決定最小值。
傳回
序列中的最小值。
例外狀況
source 是 null。
沒有任何 source 物件實 IComparable 作 OR IComparable<T> 介面。
範例
以下程式碼範例示範如何使用 Min<TSource>(IEnumerable<TSource>) 來決定一連 IComparable<T> 串物件中的最小值。
/// <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>作 ,此方法利用該實作來比較值。 否則,若型別 TSource 實 IComparable作 ,則該實作用於比較值。
若 TSource 是參考型別且來源序列為空或僅包含 的 null值,則此函數回傳 null。
在Visual Basic查詢表達式語法中,Aggregate Into Min()子句可轉譯為Min的呼叫。
另請參閱
適用於
Min<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Decimal>>)
- 來源:
- Min.cs
- 來源:
- Min.cs
- 來源:
- Min.cs
- 來源:
- Min.cs
- 來源:
- Min.cs
在序列的每個專案上叫用轉換函式,並傳回可為 null 的最小值 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的類型。
參數
- source
- IEnumerable<TSource>
一連串的值用以決定最小值。
傳回
對應於序列中最小值的值。
例外狀況
source 或 selector 為 null。
範例
以下程式碼範例示範如何用 Min<TSource>(IEnumerable<TSource>, Func<TSource,Int32>) 來確定投影值序列中的最小值。
Note
這個程式碼範例使用的方法的超載,與本文描述的具體超載不同。 若要將範例延伸到本文描述的過載,請改變函數的主體 selector 。
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> 實作來比較數值。
如果你提供一個函數 selector,將 source 的成員投影成數值型態,例如在 C# 中的 Nullable<Decimal> 或在 Visual Basic 中的 Nullable(Of Decimal),就可以將此方法應用於任意值序列。
在Visual Basic查詢表達式語法中,Aggregate Into Min()子句可轉譯為Min的呼叫。