Enumerable.Min Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Returns the minimum value in a sequence of values.
Overloads
| Name | Description |
|---|---|
|
Min(IEnumerable |
Returns the minimum value in a sequence of Single values. |
|
Min(IEnumerable |
Returns the minimum value in a sequence of nullable Single values. |
|
Min(IEnumerable |
Returns the minimum value in a sequence of nullable Int32 values. |
|
Min(IEnumerable |
Returns the minimum value in a sequence of nullable Double values. |
|
Min(IEnumerable |
Returns the minimum value in a sequence of nullable Int64 values. |
|
Min(IEnumerable |
Returns the minimum value in a sequence of Int64 values. |
|
Min(IEnumerable |
Returns the minimum value in a sequence of Int32 values. |
|
Min(IEnumerable |
Returns the minimum value in a sequence of Double values. |
|
Min(IEnumerable |
Returns the minimum value in a sequence of Decimal values. |
|
Min(IEnumerable |
Returns the minimum value in a sequence of nullable Decimal values. |
|
Min |
Invokes a transform function on each element of a generic sequence and returns the minimum resulting value. |
|
Min |
Invokes a transform function on each element of a sequence and returns the minimum nullable Int32 value. |
|
Min |
Invokes a transform function on each element of a sequence and returns the minimum Single value. |
|
Min |
Invokes a transform function on each element of a sequence and returns the minimum nullable Single value. |
|
Min |
Invokes a transform function on each element of a sequence and returns the minimum nullable Int64 value. |
|
Min |
Invokes a transform function on each element of a sequence and returns the minimum nullable Double value. |
|
Min |
Invokes a transform function on each element of a sequence and returns the minimum Decimal value. |
|
Min |
Invokes a transform function on each element of a sequence and returns the minimum Int64 value. |
|
Min |
Invokes a transform function on each element of a sequence and returns the minimum Int32 value. |
|
Min |
Invokes a transform function on each element of a sequence and returns the minimum Double value. |
|
Min |
Returns the minimum value in a generic sequence. |
|
Min |
Returns the minimum value in a generic sequence. |
|
Min |
Invokes a transform function on each element of a sequence and returns the minimum nullable Decimal value. |
Min(IEnumerable)
- Source:
- Min.cs
- Source:
- Min.cs
- Source:
- Min.cs
- Source:
- Min.cs
- Source:
- Min.cs
Returns the minimum value in a sequence of Single values.
public:
[System::Runtime::CompilerServices::Extension]
static float Min(System::Collections::Generic::IEnumerable ^ source);
public static float Min(this System.Collections.Generic.IEnumerable source);
static member Min : seq -> single
Public Function Min (source As IEnumerable(Of Single)) As Single
Parameters
- source
- IEnumerable<Single>
A sequence of Single values to determine the minimum value of.
Returns
The minimum value in the sequence.
Exceptions
source is null.
source contains no elements.
Remarks
The Min(IEnumerable
In Visual Basic query expression syntax, an Aggregate Into Min() clause translates to an invocation of Min.
See also
Applies to
Min(IEnumerable>)
- Source:
- Min.cs
- Source:
- Min.cs
- Source:
- Min.cs
- Source:
- Min.cs
- Source:
- Min.cs
Returns the minimum value in a sequence of nullable Single values.
public:
[System::Runtime::CompilerServices::Extension]
static Nullable Min(System::Collections::Generic::IEnumerable> ^ source);
public static float? Min(this System.Collections.Generic.IEnumerable source);
static member Min : seq> -> Nullable
Public Function Min (source As IEnumerable(Of Nullable(Of Single))) As Nullable(Of Single)
Parameters
- source
- IEnumerable<Nullable<Single>>
A sequence of nullable Single values to determine the minimum value of.
Returns
The value that corresponds to the minimum value in the sequence.
Exceptions
source is null.
Remarks
The Min(IEnumerable
If the source sequence is empty or contains only values that are null, this function returns null.
In Visual Basic query expression syntax, an Aggregate Into Min() clause translates to an invocation of Min.
See also
Applies to
Min(IEnumerable>)
- Source:
- Min.cs
- Source:
- Min.cs
- Source:
- Min.cs
- Source:
- Min.cs
- Source:
- Min.cs
Returns the minimum value in a sequence of nullable Int32 values.
public:
[System::Runtime::CompilerServices::Extension]
static Nullable Min(System::Collections::Generic::IEnumerable> ^ source);
public static int? Min(this System.Collections.Generic.IEnumerable source);
static member Min : seq> -> Nullable
Public Function Min (source As IEnumerable(Of Nullable(Of Integer))) As Nullable(Of Integer)
Parameters
- source
- IEnumerable<Nullable<Int32>>
A sequence of nullable Int32 values to determine the minimum value of.
Returns
The value that corresponds to the minimum value in the sequence.
Exceptions
source is null.
Examples
The following code example demonstrates how to use Min(IEnumerable
int?[] grades = { 78, 92, null, 99, 37, 81 };
int? min = grades.Min();
Console.WriteLine("The lowest grade is {0}.", min);
/*
This code produces the following output:
The lowest grade is 37.
*/
Dim grades() As Nullable(Of Integer) = {78, 92, Nothing, 99, 37, 81}
Dim min As Nullable(Of Integer) = grades.Min()
' Display the output.
Console.WriteLine($"The lowest grade is {min}")
' This code produces the following output:
'
' The lowest grade is 37
Remarks
The Min(IEnumerable
If the source sequence is empty or contains only values that are null, this function returns null.
In Visual Basic query expression syntax, an Aggregate Into Min() clause translates to an invocation of Min.
See also
Applies to
Min(IEnumerable>)
- Source:
- Min.cs
- Source:
- Min.cs
- Source:
- Min.cs
- Source:
- Min.cs
- Source:
- Min.cs
Returns the minimum value in a sequence of nullable Double values.
public:
[System::Runtime::CompilerServices::Extension]
static Nullable Min(System::Collections::Generic::IEnumerable> ^ source);
public static double? Min(this System.Collections.Generic.IEnumerable source);
static member Min : seq> -> Nullable
Public Function Min (source As IEnumerable(Of Nullable(Of Double))) As Nullable(Of Double)
Parameters
- source
- IEnumerable<Nullable<Double>>
A sequence of nullable Double values to determine the minimum value of.
Returns
The value that corresponds to the minimum value in the sequence.
Exceptions
source is null.
Remarks
The Min(IEnumerable
If the source sequence is empty or contains only values that are null, this function returns null.
In Visual Basic query expression syntax, an Aggregate Into Min() clause translates to an invocation of Min.
See also
Applies to
Min(IEnumerable>)
- Source:
- Min.cs
- Source:
- Min.cs
- Source:
- Min.cs
- Source:
- Min.cs
- Source:
- Min.cs
Returns the minimum value in a sequence of nullable Int64 values.
public:
[System::Runtime::CompilerServices::Extension]
static Nullable Min(System::Collections::Generic::IEnumerable> ^ source);
public static long? Min(this System.Collections.Generic.IEnumerable source);
static member Min : seq> -> Nullable
Public Function Min (source As IEnumerable(Of Nullable(Of Long))) As Nullable(Of Long)
Parameters
- source
- IEnumerable<Nullable<Int64>>
A sequence of nullable Int64 values to determine the minimum value of.
Returns
The value that corresponds to the minimum value in the sequence.
Exceptions
source is null.
Remarks
The Min(IEnumerable
If the source sequence is empty or contains only values that are null, this function returns null.
In Visual Basic query expression syntax, an Aggregate Into Min() clause translates to an invocation of Min.
See also
Applies to
Min(IEnumerable)
- Source:
- Min.cs
- Source:
- Min.cs
- Source:
- Min.cs
- Source:
- Min.cs
- Source:
- Min.cs
Returns the minimum value in a sequence of Int64 values.
public:
[System::Runtime::CompilerServices::Extension]
static long Min(System::Collections::Generic::IEnumerable ^ source);
public static long Min(this System.Collections.Generic.IEnumerable source);
static member Min : seq -> int64
Public Function Min (source As IEnumerable(Of Long)) As Long
Parameters
- source
- IEnumerable<Int64>
A sequence of Int64 values to determine the minimum value of.
Returns
The minimum value in the sequence.
Exceptions
source is null.
source contains no elements.
Remarks
The Min(IEnumerable
In Visual Basic query expression syntax, an Aggregate Into Min() clause translates to an invocation of Min.
See also
Applies to
Min(IEnumerable)
- Source:
- Min.cs
- Source:
- Min.cs
- Source:
- Min.cs
- Source:
- Min.cs
- Source:
- Min.cs
Returns the minimum value in a sequence of Int32 values.
public:
[System::Runtime::CompilerServices::Extension]
static int Min(System::Collections::Generic::IEnumerable ^ source);
public static int Min(this System.Collections.Generic.IEnumerable source);
static member Min : seq -> int
Public Function Min (source As IEnumerable(Of Integer)) As Integer
Parameters
- source
- IEnumerable<Int32>
A sequence of Int32 values to determine the minimum value of.
Returns
The minimum value in the sequence.
Exceptions
source is null.
source contains no elements.
Remarks
The Min(IEnumerable
In Visual Basic query expression syntax, an Aggregate Into Min() clause translates to an invocation of Min.
See also
Applies to
Min(IEnumerable)
- Source:
- Min.cs
- Source:
- Min.cs
- Source:
- Min.cs
- Source:
- Min.cs
- Source:
- Min.cs
Returns the minimum value in a sequence of Double values.
public:
[System::Runtime::CompilerServices::Extension]
static double Min(System::Collections::Generic::IEnumerable ^ source);
public static double Min(this System.Collections.Generic.IEnumerable source);
static member Min : seq -> double
Public Function Min (source As IEnumerable(Of Double)) As Double
Parameters
- source
- IEnumerable<Double>
A sequence of Double values to determine the minimum value of.
Returns
The minimum value in the sequence.
Exceptions
source is null.
source contains no elements.
Examples
The following code example demonstrates how to use Min(IEnumerable
double[] doubles = { 1.5E+104, 9E+103, -2E+103 };
double min = doubles.Min();
Console.WriteLine("The smallest number is {0}.", min);
/*
This code produces the following output:
The smallest number is -2E+103.
*/
' Create an array of double values.
Dim doubles() As Double = {1.5E+104, 9.0E+103, -2.0E+103}
' Determine the smallest number in the array.
Dim min As Double = doubles.Min()
' Display the result.
Console.WriteLine($"The smallest number is {min}")
' This code produces the following output:
'
' The smallest number is -2E+103
Remarks
The Min(IEnumerable
In Visual Basic query expression syntax, an Aggregate Into Min() clause translates to an invocation of Min.
See also
Applies to
Min(IEnumerable)
- Source:
- Min.cs
- Source:
- Min.cs
- Source:
- Min.cs
- Source:
- Min.cs
- Source:
- Min.cs
Returns the minimum value in a sequence of Decimal values.
public:
[System::Runtime::CompilerServices::Extension]
static System::Decimal Min(System::Collections::Generic::IEnumerable ^ source);
public static decimal Min(this System.Collections.Generic.IEnumerable source);
static member Min : seq -> decimal
Public Function Min (source As IEnumerable(Of Decimal)) As Decimal
Parameters
- source
- IEnumerable<Decimal>
A sequence of Decimal values to determine the minimum value of.
Returns
The minimum value in the sequence.
Exceptions
source is null.
source contains no elements.
Remarks
The Min(IEnumerable
In Visual Basic query expression syntax, an Aggregate Into Min() clause translates to an invocation of Min.
See also
Applies to
Min(IEnumerable>)
- Source:
- Min.cs
- Source:
- Min.cs
- Source:
- Min.cs
- Source:
- Min.cs
- Source:
- Min.cs
Returns the minimum value in a sequence of nullable Decimal values.
public:
[System::Runtime::CompilerServices::Extension]
static Nullable Min(System::Collections::Generic::IEnumerable> ^ source);
public static decimal? Min(this System.Collections.Generic.IEnumerable source);
static member Min : seq> -> Nullable
Public Function Min (source As IEnumerable(Of Nullable(Of Decimal))) As Nullable(Of Decimal)
Parameters
- source
- IEnumerable<Nullable<Decimal>>
A sequence of nullable Decimal values to determine the minimum value of.
Returns
The value that corresponds to the minimum value in the sequence.
Exceptions
source is null.
Remarks
The Min(IEnumerable
If the source sequence is empty or contains only values that are null, this function returns null.
In Visual Basic query expression syntax, an Aggregate Into Min() clause translates to an invocation of Min.
See also
Applies to
Min(IEnumerable, Func)
- Source:
- Min.cs
- Source:
- Min.cs
- Source:
- Min.cs
- Source:
- Min.cs
- Source:
- Min.cs
Invokes a transform function on each element of a generic sequence and returns the minimum resulting value.
public:
generic
[System::Runtime::CompilerServices::Extension]
static TResult Min(System::Collections::Generic::IEnumerable ^ source, Func ^ selector);
public static TResult Min(this System.Collections.Generic.IEnumerable source, Func selector);
public static TResult? Min(this System.Collections.Generic.IEnumerable source, Func selector);
static member Min : seq<'Source> * Func<'Source, 'Result> -> 'Result
Public Function Min(Of TSource, TResult) (source As IEnumerable(Of TSource), selector As Func(Of TSource, TResult)) As TResult
Type Parameters
- TSource
The type of the elements of source.
- TResult
The type of the value returned by selector.
Parameters
- source
-
IEnumerable
A sequence of values to determine the minimum value of.
- selector
-
Func
A transform function to apply to each element.
Returns
The minimum value in the sequence.
Exceptions
source or selector is null.
Examples
The following code example demonstrates how to use Min
Note
This code example uses an overload of the method that's different from the specific overload that this article describes. To extend the example to the overload that this article describes, change the body of the selector function.
class Pet
{
public string Name { get; set; }
public int Age { get; set; }
}
public static void MinEx4()
{
Pet[] pets = { new Pet { Name="Barley", Age=8 },
new Pet { Name="Boots", Age=4 },
new Pet { Name="Whiskers", Age=1 } };
int min = pets.Min(pet => pet.Age);
Console.WriteLine("The youngest animal is age {0}.", min);
}
/*
This code produces the following output:
The youngest animal is age 1.
*/
Structure Pet
Public Name As String
Public Age As Integer
End Structure
Sub MinEx4()
' Create an array of Pet objects.
Dim pets() As Pet = {New Pet With {.Name = "Barley", .Age = 8},
New Pet With {.Name = "Boots", .Age = 4},
New Pet With {.Name = "Whiskers", .Age = 1}}
' Find the youngest pet by passing a
' lambda expression to the Min() method.
Dim min As Integer = pets.Min(Function(pet) pet.Age)
' Display the result.
Console.WriteLine($"The youngest pet is age {min}")
End Sub
' This code produces the following output:
'
' The youngest pet is age 1
Remarks
If type TResult implements IComparableTResult implements IComparable, that implementation is used to compare values.
In Visual Basic query expression syntax, an Aggregate Into Min() clause translates to an invocation of Min.
See also
Applies to
Min(IEnumerable, Func>)
- Source:
- Min.cs
- Source:
- Min.cs
- Source:
- Min.cs
- Source:
- Min.cs
- Source:
- Min.cs
Invokes a transform function on each element of a sequence and returns the minimum nullable Int32 value.
public:
generic
[System::Runtime::CompilerServices::Extension]
static Nullable Min(System::Collections::Generic::IEnumerable ^ source, Func> ^ selector);
public static int? Min(this System.Collections.Generic.IEnumerable source, Func selector);
static member Min : seq<'Source> * Func<'Source, Nullable> -> Nullable
Public Function Min(Of TSource) (source As IEnumerable(Of TSource), selector As Func(Of TSource, Nullable(Of Integer))) As Nullable(Of Integer)
Type Parameters
- TSource
The type of the elements of source.
Parameters
- source
-
IEnumerable
A sequence of values to determine the minimum value of.
Returns
The value that corresponds to the minimum value in the sequence.
Exceptions
source or selector is null.
Examples
The following code example demonstrates how to use Min
Note
This code example uses an overload of the method that's different from the specific overload that this article describes. To extend the example to the overload that this article describes, change the body of the selector function.
class Pet
{
public string Name { get; set; }
public int Age { get; set; }
}
public static void MinEx4()
{
Pet[] pets = { new Pet { Name="Barley", Age=8 },
new Pet { Name="Boots", Age=4 },
new Pet { Name="Whiskers", Age=1 } };
int min = pets.Min(pet => pet.Age);
Console.WriteLine("The youngest animal is age {0}.", min);
}
/*
This code produces the following output:
The youngest animal is age 1.
*/
Structure Pet
Public Name As String
Public Age As Integer
End Structure
Sub MinEx4()
' Create an array of Pet objects.
Dim pets() As Pet = {New Pet With {.Name = "Barley", .Age = 8},
New Pet With {.Name = "Boots", .Age = 4},
New Pet With {.Name = "Whiskers", .Age = 1}}
' Find the youngest pet by passing a
' lambda expression to the Min() method.
Dim min As Integer = pets.Min(Function(pet) pet.Age)
' Display the result.
Console.WriteLine($"The youngest pet is age {min}")
End Sub
' This code produces the following output:
'
' The youngest pet is age 1
Remarks
The Min
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 in C# or Nullable(Of Int32) in Visual Basic.
In Visual Basic query expression syntax, an Aggregate Into Min() clause translates to an invocation of Min.
See also
Applies to
Min(IEnumerable, Func)
- Source:
- Min.cs
- Source:
- Min.cs
- Source:
- Min.cs
- Source:
- Min.cs
- Source:
- Min.cs
Invokes a transform function on each element of a sequence and returns the minimum Single value.
public:
generic
[System::Runtime::CompilerServices::Extension]
static float Min(System::Collections::Generic::IEnumerable ^ source, Func ^ selector);
public static float Min(this System.Collections.Generic.IEnumerable source, Func selector);
static member Min : seq<'Source> * Func<'Source, single> -> single
Public Function Min(Of TSource) (source As IEnumerable(Of TSource), selector As Func(Of TSource, Single)) As Single
Type Parameters
- TSource
The type of the elements of source.
Parameters
- source
-
IEnumerable
A sequence of values to determine the minimum value of.
- selector
-
Func
Single>
A transform function to apply to each element.
Returns
The minimum value in the sequence.
Exceptions
source or selector is null.
source contains no elements.
Examples
The following code example demonstrates how to use Min
Note
This code example uses an overload of the method that's different from the specific overload that this article describes. To extend the example to the overload that this article describes, change the body of the selector function.
class Pet
{
public string Name { get; set; }
public int Age { get; set; }
}
public static void MinEx4()
{
Pet[] pets = { new Pet { Name="Barley", Age=8 },
new Pet { Name="Boots", Age=4 },
new Pet { Name="Whiskers", Age=1 } };
int min = pets.Min(pet => pet.Age);
Console.WriteLine("The youngest animal is age {0}.", min);
}
/*
This code produces the following output:
The youngest animal is age 1.
*/
Structure Pet
Public Name As String
Public Age As Integer
End Structure
Sub MinEx4()
' Create an array of Pet objects.
Dim pets() As Pet = {New Pet With {.Name = "Barley", .Age = 8},
New Pet With {.Name = "Boots", .Age = 4},
New Pet With {.Name = "Whiskers", .Age = 1}}
' Find the youngest pet by passing a
' lambda expression to the Min() method.
Dim min As Integer = pets.Min(Function(pet) pet.Age)
' Display the result.
Console.WriteLine($"The youngest pet is age {min}")
End Sub
' This code produces the following output:
'
' The youngest pet is age 1
Remarks
The Min
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.
In Visual Basic query expression syntax, an Aggregate Into Min() clause translates to an invocation of Min.
See also
Applies to
Min(IEnumerable, Func>)
- Source:
- Min.cs
- Source:
- Min.cs
- Source:
- Min.cs
- Source:
- Min.cs
- Source:
- Min.cs
Invokes a transform function on each element of a sequence and returns the minimum nullable Single value.
public:
generic
[System::Runtime::CompilerServices::Extension]
static Nullable Min(System::Collections::Generic::IEnumerable ^ source, Func> ^ selector);
public static float? Min(this System.Collections.Generic.IEnumerable source, Func selector);
static member Min : seq<'Source> * Func<'Source, Nullable> -> Nullable
Public Function Min(Of TSource) (source As IEnumerable(Of TSource), selector As Func(Of TSource, Nullable(Of Single))) As Nullable(Of Single)
Type Parameters
- TSource
The type of the elements of source.
Parameters
- source
-
IEnumerable
A sequence of values to determine the minimum value of.
Returns
The value that corresponds to the minimum value in the sequence.
Exceptions
source or selector is null.
Examples
The following code example demonstrates how to use Min
Note
This code example uses an overload of the method that's different from the specific overload that this article describes. To extend the example to the overload that this article describes, change the body of the selector function.
class Pet
{
public string Name { get; set; }
public int Age { get; set; }
}
public static void MinEx4()
{
Pet[] pets = { new Pet { Name="Barley", Age=8 },
new Pet { Name="Boots", Age=4 },
new Pet { Name="Whiskers", Age=1 } };
int min = pets.Min(pet => pet.Age);
Console.WriteLine("The youngest animal is age {0}.", min);
}
/*
This code produces the following output:
The youngest animal is age 1.
*/
Structure Pet
Public Name As String
Public Age As Integer
End Structure
Sub MinEx4()
' Create an array of Pet objects.
Dim pets() As Pet = {New Pet With {.Name = "Barley", .Age = 8},
New Pet With {.Name = "Boots", .Age = 4},
New Pet With {.Name = "Whiskers", .Age = 1}}
' Find the youngest pet by passing a
' lambda expression to the Min() method.
Dim min As Integer = pets.Min(Function(pet) pet.Age)
' Display the result.
Console.WriteLine($"The youngest pet is age {min}")
End Sub
' This code produces the following output:
'
' The youngest pet is age 1
Remarks
The Min
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 in C# or Nullable(Of Single) in Visual Basic.
In Visual Basic query expression syntax, an Aggregate Into Min() clause translates to an invocation of Min.
See also
Applies to
Min(IEnumerable, Func>)
- Source:
- Min.cs
- Source:
- Min.cs
- Source:
- Min.cs
- Source:
- Min.cs
- Source:
- Min.cs
Invokes a transform function on each element of a sequence and returns the minimum nullable Int64 value.
public:
generic
[System::Runtime::CompilerServices::Extension]
static Nullable Min(System::Collections::Generic::IEnumerable ^ source, Func> ^ selector);
public static long? Min(this System.Collections.Generic.IEnumerable source, Func selector);
static member Min : seq<'Source> * Func<'Source, Nullable> -> Nullable
Public Function Min(Of TSource) (source As IEnumerable(Of TSource), selector As Func(Of TSource, Nullable(Of Long))) As Nullable(Of Long)
Type Parameters
- TSource
The type of the elements of source.
Parameters
- source
-
IEnumerable
A sequence of values to determine the minimum value of.
Returns
The value that corresponds to the minimum value in the sequence.
Exceptions
source or selector is null.
Examples
The following code example demonstrates how to use Min
Note
This code example uses an overload of the method that's different from the specific overload that this article describes. To extend the example to the overload that this article describes, change the body of the selector function.
class Pet
{
public string Name { get; set; }
public int Age { get; set; }
}
public static void MinEx4()
{
Pet[] pets = { new Pet { Name="Barley", Age=8 },
new Pet { Name="Boots", Age=4 },
new Pet { Name="Whiskers", Age=1 } };
int min = pets.Min(pet => pet.Age);
Console.WriteLine("The youngest animal is age {0}.", min);
}
/*
This code produces the following output:
The youngest animal is age 1.
*/
Structure Pet
Public Name As String
Public Age As Integer
End Structure
Sub MinEx4()
' Create an array of Pet objects.
Dim pets() As Pet = {New Pet With {.Name = "Barley", .Age = 8},
New Pet With {.Name = "Boots", .Age = 4},
New Pet With {.Name = "Whiskers", .Age = 1}}
' Find the youngest pet by passing a
' lambda expression to the Min() method.
Dim min As Integer = pets.Min(Function(pet) pet.Age)
' Display the result.
Console.WriteLine($"The youngest pet is age {min}")
End Sub
' This code produces the following output:
'
' The youngest pet is age 1
Remarks
The Min
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 in C# or Nullable(Of Int64) in Visual Basic.
In Visual Basic query expression syntax, an Aggregate Into Min() clause translates to an invocation of Min.
See also
Applies to
Min(IEnumerable, Func>)
- Source:
- Min.cs
- Source:
- Min.cs
- Source:
- Min.cs
- Source:
- Min.cs
- Source:
- Min.cs
Invokes a transform function on each element of a sequence and returns the minimum nullable Double value.
public:
generic
[System::Runtime::CompilerServices::Extension]
static Nullable Min(System::Collections::Generic::IEnumerable ^ source, Func> ^ selector);
public static double? Min(this System.Collections.Generic.IEnumerable source, Func selector);
static member Min : seq<'Source> * Func<'Source, Nullable> -> Nullable
Public Function Min(Of TSource) (source As IEnumerable(Of TSource), selector As Func(Of TSource, Nullable(Of Double))) As Nullable(Of Double)
Type Parameters
- TSource
The type of the elements of source.
Parameters
- source
-
IEnumerable
A sequence of values to determine the minimum value of.
Returns
The value that corresponds to the minimum value in the sequence.
Exceptions
source or selector is null.
Examples
The following code example demonstrates how to use Min
Note
This code example uses an overload of the method that's different from the specific overload that this article describes. To extend the example to the overload that this article describes, change the body of the selector function.
class Pet
{
public string Name { get; set; }
public int Age { get; set; }
}
public static void MinEx4()
{
Pet[] pets = { new Pet { Name="Barley", Age=8 },
new Pet { Name="Boots", Age=4 },
new Pet { Name="Whiskers", Age=1 } };
int min = pets.Min(pet => pet.Age);
Console.WriteLine("The youngest animal is age {0}.", min);
}
/*
This code produces the following output:
The youngest animal is age 1.
*/
Structure Pet
Public Name As String
Public Age As Integer
End Structure
Sub MinEx4()
' Create an array of Pet objects.
Dim pets() As Pet = {New Pet With {.Name = "Barley", .Age = 8},
New Pet With {.Name = "Boots", .Age = 4},
New Pet With {.Name = "Whiskers", .Age = 1}}
' Find the youngest pet by passing a
' lambda expression to the Min() method.
Dim min As Integer = pets.Min(Function(pet) pet.Age)
' Display the result.
Console.WriteLine($"The youngest pet is age {min}")
End Sub
' This code produces the following output:
'
' The youngest pet is age 1
Remarks
The Min
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 in C# or Nullable(Of Double) in Visual Basic.
In Visual Basic query expression syntax, an Aggregate Into Min() clause translates to an invocation of Min.
See also
Applies to
Min(IEnumerable, Func)
- Source:
- Min.cs
- Source:
- Min.cs
- Source:
- Min.cs
- Source:
- Min.cs
- Source:
- Min.cs
Invokes a transform function on each element of a sequence and returns the minimum Decimal value.
public:
generic
[System::Runtime::CompilerServices::Extension]
static System::Decimal Min(System::Collections::Generic::IEnumerable ^ source, Func ^ selector);
public static decimal Min(this System.Collections.Generic.IEnumerable source, Func selector);
static member Min : seq<'Source> * Func<'Source, decimal> -> decimal
Public Function Min(Of TSource) (source As IEnumerable(Of TSource), selector As Func(Of TSource, Decimal)) As Decimal
Type Parameters
- TSource
The type of the elements of source.
Parameters
- source
-
IEnumerable
A sequence of values to determine the minimum value of.
- selector
-
Func
Decimal>
A transform function to apply to each element.
Returns
The minimum value in the sequence.
Exceptions
source or selector is null.
source contains no elements.
Examples
The following code example demonstrates how to use Min
Note
This code example uses an overload of the method that's different from the specific overload that this article describes. To extend the example to the overload that this article describes, change the body of the selector function.
class Pet
{
public string Name { get; set; }
public int Age { get; set; }
}
public static void MinEx4()
{
Pet[] pets = { new Pet { Name="Barley", Age=8 },
new Pet { Name="Boots", Age=4 },
new Pet { Name="Whiskers", Age=1 } };
int min = pets.Min(pet => pet.Age);
Console.WriteLine("The youngest animal is age {0}.", min);
}
/*
This code produces the following output:
The youngest animal is age 1.
*/
Structure Pet
Public Name As String
Public Age As Integer
End Structure
Sub MinEx4()
' Create an array of Pet objects.
Dim pets() As Pet = {New Pet With {.Name = "Barley", .Age = 8},
New Pet With {.Name = "Boots", .Age = 4},
New Pet With {.Name = "Whiskers", .Age = 1}}
' Find the youngest pet by passing a
' lambda expression to the Min() method.
Dim min As Integer = pets.Min(Function(pet) pet.Age)
' Display the result.
Console.WriteLine($"The youngest pet is age {min}")
End Sub
' This code produces the following output:
'
' The youngest pet is age 1
Remarks
The Min
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.
In Visual Basic query expression syntax, an Aggregate Into Min() clause translates to an invocation of Min.
See also
Applies to
Min(IEnumerable, Func)
- Source:
- Min.cs
- Source:
- Min.cs
- Source:
- Min.cs
- Source:
- Min.cs
- Source:
- Min.cs
Invokes a transform function on each element of a sequence and returns the minimum Int64 value.
public:
generic
[System::Runtime::CompilerServices::Extension]
static long Min(System::Collections::Generic::IEnumerable ^ source, Func ^ selector);
public static long Min(this System.Collections.Generic.IEnumerable source, Func selector);
static member Min : seq<'Source> * Func<'Source, int64> -> int64
Public Function Min(Of TSource) (source As IEnumerable(Of TSource), selector As Func(Of TSource, Long)) As Long
Type Parameters
- TSource
The type of the elements of source.
Parameters
- source
-
IEnumerable
A sequence of values to determine the minimum value of.
- selector
-
Func
Int64>
A transform function to apply to each element.
Returns
The minimum value in the sequence.
Exceptions
source or selector is null.
source contains no elements.
Examples
The following code example demonstrates how to use Min
Note
This code example uses an overload of the method that's different from the specific overload that this article describes. To extend the example to the overload that this article describes, change the body of the selector function.
class Pet
{
public string Name { get; set; }
public int Age { get; set; }
}
public static void MinEx4()
{
Pet[] pets = { new Pet { Name="Barley", Age=8 },
new Pet { Name="Boots", Age=4 },
new Pet { Name="Whiskers", Age=1 } };
int min = pets.Min(pet => pet.Age);
Console.WriteLine("The youngest animal is age {0}.", min);
}
/*
This code produces the following output:
The youngest animal is age 1.
*/
Structure Pet
Public Name As String
Public Age As Integer
End Structure
Sub MinEx4()
' Create an array of Pet objects.
Dim pets() As Pet = {New Pet With {.Name = "Barley", .Age = 8},
New Pet With {.Name = "Boots", .Age = 4},
New Pet With {.Name = "Whiskers", .Age = 1}}
' Find the youngest pet by passing a
' lambda expression to the Min() method.
Dim min As Integer = pets.Min(Function(pet) pet.Age)
' Display the result.
Console.WriteLine($"The youngest pet is age {min}")
End Sub
' This code produces the following output:
'
' The youngest pet is age 1
Remarks
The Min
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.
In Visual Basic query expression syntax, an Aggregate Into Min() clause translates to an invocation of Min.
See also
Applies to
Min(IEnumerable, Func)
- Source:
- Min.cs
- Source:
- Min.cs
- Source:
- Min.cs
- Source:
- Min.cs
- Source:
- Min.cs
Invokes a transform function on each element of a sequence and returns the minimum Int32 value.
public:
generic
[System::Runtime::CompilerServices::Extension]
static int Min(System::Collections::Generic::IEnumerable ^ source, Func ^ selector);
public static int Min(this System.Collections.Generic.IEnumerable source, Func selector);
static member Min : seq<'Source> * Func<'Source, int> -> int
Public Function Min(Of TSource) (source As IEnumerable(Of TSource), selector As Func(Of TSource, Integer)) As Integer
Type Parameters
- TSource
The type of the elements of source.
Parameters
- source
-
IEnumerable
A sequence of values to determine the minimum value of.
- selector
-
Func
Int32>
A transform function to apply to each element.
Returns
The minimum value in the sequence.
Exceptions
source or selector is null.
source contains no elements.
Examples
The following code example demonstrates how to use Min
class Pet
{
public string Name { get; set; }
public int Age { get; set; }
}
public static void MinEx4()
{
Pet[] pets = { new Pet { Name="Barley", Age=8 },
new Pet { Name="Boots", Age=4 },
new Pet { Name="Whiskers", Age=1 } };
int min = pets.Min(pet => pet.Age);
Console.WriteLine("The youngest animal is age {0}.", min);
}
/*
This code produces the following output:
The youngest animal is age 1.
*/
Structure Pet
Public Name As String
Public Age As Integer
End Structure
Sub MinEx4()
' Create an array of Pet objects.
Dim pets() As Pet = {New Pet With {.Name = "Barley", .Age = 8},
New Pet With {.Name = "Boots", .Age = 4},
New Pet With {.Name = "Whiskers", .Age = 1}}
' Find the youngest pet by passing a
' lambda expression to the Min() method.
Dim min As Integer = pets.Min(Function(pet) pet.Age)
' Display the result.
Console.WriteLine($"The youngest pet is age {min}")
End Sub
' This code produces the following output:
'
' The youngest pet is age 1
Remarks
The Min
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.
In Visual Basic query expression syntax, an Aggregate Into Min() clause translates to an invocation of Min.
See also
Applies to
Min(IEnumerable, Func)
- Source:
- Min.cs
- Source:
- Min.cs
- Source:
- Min.cs
- Source:
- Min.cs
- Source:
- Min.cs
Invokes a transform function on each element of a sequence and returns the minimum Double value.
public:
generic
[System::Runtime::CompilerServices::Extension]
static double Min(System::Collections::Generic::IEnumerable ^ source, Func ^ selector);
public static double Min(this System.Collections.Generic.IEnumerable source, Func selector);
static member Min : seq<'Source> * Func<'Source, double> -> double
Public Function Min(Of TSource) (source As IEnumerable(Of TSource), selector As Func(Of TSource, Double)) As Double
Type Parameters
- TSource
The type of the elements of source.
Parameters
- source
-
IEnumerable
A sequence of values to determine the minimum value of.
- selector
-
Func
Double>
A transform function to apply to each element.
Returns
The minimum value in the sequence.
Exceptions
source or selector is null.
source contains no elements.
Examples
The following code example demonstrates how to use Min
Note
This code example uses an overload of the method that's different from the specific overload that this article describes. To extend the example to the overload that this article describes, change the body of the selector function.
class Pet
{
public string Name { get; set; }
public int Age { get; set; }
}
public static void MinEx4()
{
Pet[] pets = { new Pet { Name="Barley", Age=8 },
new Pet { Name="Boots", Age=4 },
new Pet { Name="Whiskers", Age=1 } };
int min = pets.Min(pet => pet.Age);
Console.WriteLine("The youngest animal is age {0}.", min);
}
/*
This code produces the following output:
The youngest animal is age 1.
*/
Structure Pet
Public Name As String
Public Age As Integer
End Structure
Sub MinEx4()
' Create an array of Pet objects.
Dim pets() As Pet = {New Pet With {.Name = "Barley", .Age = 8},
New Pet With {.Name = "Boots", .Age = 4},
New Pet With {.Name = "Whiskers", .Age = 1}}
' Find the youngest pet by passing a
' lambda expression to the Min() method.
Dim min As Integer = pets.Min(Function(pet) pet.Age)
' Display the result.
Console.WriteLine($"The youngest pet is age {min}")
End Sub
' This code produces the following output:
'
' The youngest pet is age 1
Remarks
The Min
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.
In Visual Basic query expression syntax, an Aggregate Into Min() clause translates to an invocation of Min.
See also
Applies to
Min(IEnumerable, IComparer)
- Source:
- Min.cs
- Source:
- Min.cs
- Source:
- Min.cs
- Source:
- Min.cs
- Source:
- Min.cs
Returns the minimum value in a generic sequence.
public:
generic
[System::Runtime::CompilerServices::Extension]
static TSource Min(System::Collections::Generic::IEnumerable ^ source, System::Collections::Generic::IComparer ^ comparer);
public static TSource? Min(this System.Collections.Generic.IEnumerable source, System.Collections.Generic.IComparer? comparer);
static member Min : seq<'Source> * System.Collections.Generic.IComparer<'Source> -> 'Source
Public Function Min(Of TSource) (source As IEnumerable(Of TSource), comparer As IComparer(Of TSource)) As TSource
Type Parameters
- TSource
The type of the elements of source.
Parameters
- source
-
IEnumerable
A sequence of values to determine the minimum value of.
Returns
The minimum value in the sequence.
Exceptions
source is null.
No object in source implements the IComparable or IComparable
Remarks
If type TSource implements IComparableTSource implements IComparable, that implementation is used to compare values.
If TSource is a reference type and the source sequence is empty or contains only values that are null, this method returns null.
In Visual Basic query expression syntax, an Aggregate Into Min() clause translates to an invocation of Min.
Applies to
Min(IEnumerable)
- Source:
- Min.cs
- Source:
- Min.cs
- Source:
- Min.cs
- Source:
- Min.cs
- Source:
- Min.cs
Returns the minimum value in a generic sequence.
public:
generic
[System::Runtime::CompilerServices::Extension]
static TSource Min(System::Collections::Generic::IEnumerable ^ source);
public static TSource Min(this System.Collections.Generic.IEnumerable source);
public static TSource? Min(this System.Collections.Generic.IEnumerable source);
static member Min : seq<'Source> -> 'Source
Public Function Min(Of TSource) (source As IEnumerable(Of TSource)) As TSource
Type Parameters
- TSource
The type of the elements of source.
Parameters
- source
-
IEnumerable
A sequence of values to determine the minimum value of.
Returns
The minimum value in the sequence.
Exceptions
source is null.
No object in source implements the IComparable or IComparable
Examples
The following code example demonstrates how to use Min
///
/// This class implements IComparable in order to
/// be able to compare different Pet objects.
///
class Pet : IComparable
{
public string Name { get; set; }
public int Age { get; set; }
///
/// Compares this Pet's age to another Pet's age.
///
/// The Pet to compare this Pet to.
/// -1 if this Pet's age is smaller,
/// 0 if the Pets' ages are equal, or
/// 1 if this Pet's age is greater.
int IComparable.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
'''
''' Compares this Pet's age to another Pet's age.
'''
''' The Pet to compare this Pet to.
''' -1 if this Pet's age is smaller,
''' 0 if the Pets' ages are equal,
''' or 1 if this Pet's age is greater.
Function CompareTo(ByVal other As Pet) As Integer _
Implements IComparable(Of Pet).CompareTo
If (other.Age > Me.Age) Then
Return -1
ElseIf (other.Age = Me.Age) Then
Return 0
Else
Return 1
End If
End Function
End Class
Sub MinEx3()
' Create an array of Pet objects.
Dim pets() As Pet = {New Pet With {.Name = "Barley", .Age = 8},
New Pet With {.Name = "Boots", .Age = 4},
New Pet With {.Name = "Whiskers", .Age = 1}}
' Determine the "minimum" pet in the array,
' according to the custom CompareTo() implementation.
Dim min As Pet = pets.Min()
' Display the result.
Console.WriteLine($"The 'minimum' pet is {min.Name}")
End Sub
' This code produces the following output:
'
' The 'minimum' pet is Whiskers
Remarks
If type TSource implements IComparableTSource implements IComparable, that implementation is used to compare values.
If TSource is a reference type and the source sequence is empty or contains only values that are null, this function returns null.
In Visual Basic query expression syntax, an Aggregate Into Min() clause translates to an invocation of Min.
See also
Applies to
Min(IEnumerable, Func>)
- Source:
- Min.cs
- Source:
- Min.cs
- Source:
- Min.cs
- Source:
- Min.cs
- Source:
- Min.cs
Invokes a transform function on each element of a sequence and returns the minimum nullable Decimal value.
public:
generic
[System::Runtime::CompilerServices::Extension]
static Nullable Min(System::Collections::Generic::IEnumerable ^ source, Func> ^ selector);
public static decimal? Min(this System.Collections.Generic.IEnumerable source, Func selector);
static member Min : seq<'Source> * Func<'Source, Nullable> -> Nullable
Public Function Min(Of TSource) (source As IEnumerable(Of TSource), selector As Func(Of TSource, Nullable(Of Decimal))) As Nullable(Of Decimal)
Type Parameters
- TSource
The type of the elements of source.
Parameters
- source
-
IEnumerable
A sequence of values to determine the minimum value of.
Returns
The value that corresponds to the minimum value in the sequence.
Exceptions
source or selector is null.
Examples
The following code example demonstrates how to use Min
Note
This code example uses an overload of the method that's different from the specific overload that this article describes. To extend the example to the overload that this article describes, change the body of the selector function.
class Pet
{
public string Name { get; set; }
public int Age { get; set; }
}
public static void MinEx4()
{
Pet[] pets = { new Pet { Name="Barley", Age=8 },
new Pet { Name="Boots", Age=4 },
new Pet { Name="Whiskers", Age=1 } };
int min = pets.Min(pet => pet.Age);
Console.WriteLine("The youngest animal is age {0}.", min);
}
/*
This code produces the following output:
The youngest animal is age 1.
*/
Structure Pet
Public Name As String
Public Age As Integer
End Structure
Sub MinEx4()
' Create an array of Pet objects.
Dim pets() As Pet = {New Pet With {.Name = "Barley", .Age = 8},
New Pet With {.Name = "Boots", .Age = 4},
New Pet With {.Name = "Whiskers", .Age = 1}}
' Find the youngest pet by passing a
' lambda expression to the Min() method.
Dim min As Integer = pets.Min(Function(pet) pet.Age)
' Display the result.
Console.WriteLine($"The youngest pet is age {min}")
End Sub
' This code produces the following output:
'
' The youngest pet is age 1
Remarks
The Min
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 in C# or Nullable(Of Decimal) in Visual Basic.
In Visual Basic query expression syntax, an Aggregate Into Min() clause translates to an invocation of Min.