Queryable.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.
Overloads
| Name | Description |
|---|---|
|
Min |
Invokes a projection function on each element of a generic IQueryable |
|
Min |
Returns the minimum value in a generic IQueryable |
|
Min |
Returns the minimum value of a generic IQueryable |
Min(IQueryable, Expression>)
- Source:
- Queryable.cs
- Source:
- Queryable.cs
- Source:
- Queryable.cs
- Source:
- Queryable.cs
- Source:
- Queryable.cs
Invokes a projection function on each element of a generic IQueryable
public:
generic
[System::Runtime::CompilerServices::Extension]
static TResult Min(System::Linq::IQueryable ^ source, System::Linq::Expressions::Expression ^> ^ selector);
public static TResult Min(this System.Linq.IQueryable source, System.Linq.Expressions.Expression> selector);
public static TResult? Min(this System.Linq.IQueryable source, System.Linq.Expressions.Expression> selector);
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Enumerating collections as IQueryable can require creating new generic types or methods, which requires creating code at runtime. This may not work when AOT compiling.")]
public static TResult? Min(this System.Linq.IQueryable source, System.Linq.Expressions.Expression> selector);
static member Min : System.Linq.IQueryable<'Source> * System.Linq.Expressions.Expression> -> 'Result
[]
static member Min : System.Linq.IQueryable<'Source> * System.Linq.Expressions.Expression> -> 'Result
Public Function Min(Of TSource, TResult) (source As IQueryable(Of TSource), selector As Expression(Of Func(Of TSource, TResult))) As TResult
Type Parameters
- TSource
The type of the elements of source.
- TResult
The type of the value returned by the function represented by selector.
Parameters
- source
-
IQueryable
A sequence of values to determine the minimum of.
- selector
-
Expression<Func
>
A projection function to apply to each element.
Returns
The minimum value in the sequence.
- Attributes
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 MinEx2()
{
Pet[] pets = { new Pet { Name="Barley", Age=8 },
new Pet { Name="Boots", Age=4 },
new Pet { Name="Whiskers", Age=1 } };
// Get the Pet object that has the smallest Age value.
int min = pets.AsQueryable().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
Shared Sub MinEx2()
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}}
' Get the Pet object that has the smallest Age value.
Dim min As Integer = pets.AsQueryable().Min(Function(pet) pet.Age)
MsgBox(String.Format("The youngest animal is age {0}.", min))
End Sub
'This code produces the following output:
'The youngest animal is age 1.
Remarks
This method has at least one parameter of type Expression
The Minsource parameter.
The query behavior that occurs as a result of executing an expression tree that represents calling Minsource parameter. The expected behavior is that it invokes selector on each element in source and returns the minimum value.
Applies to
Min(IQueryable, IComparer)
- Source:
- Queryable.cs
- Source:
- Queryable.cs
- Source:
- Queryable.cs
- Source:
- Queryable.cs
- Source:
- Queryable.cs
Returns the minimum value in a generic IQueryable
public:
generic
[System::Runtime::CompilerServices::Extension]
static TSource Min(System::Linq::IQueryable ^ source, System::Collections::Generic::IComparer ^ comparer);
public static TSource? Min(this System.Linq.IQueryable source, System.Collections.Generic.IComparer? comparer);
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Enumerating collections as IQueryable can require creating new generic types or methods, which requires creating code at runtime. This may not work when AOT compiling.")]
public static TSource? Min(this System.Linq.IQueryable source, System.Collections.Generic.IComparer? comparer);
static member Min : System.Linq.IQueryable<'Source> * System.Collections.Generic.IComparer<'Source> -> 'Source
[]
static member Min : System.Linq.IQueryable<'Source> * System.Collections.Generic.IComparer<'Source> -> 'Source
Public Function Min(Of TSource) (source As IQueryable(Of TSource), comparer As IComparer(Of TSource)) As TSource
Type Parameters
- TSource
The type of the elements of source.
Parameters
- source
-
IQueryable
A sequence of values to determine the minimum value of.
Returns
The minimum value in the sequence.
- Attributes
Exceptions
source is null.
No object in source implements the IComparable or IComparable
Applies to
Min(IQueryable)
- Source:
- Queryable.cs
- Source:
- Queryable.cs
- Source:
- Queryable.cs
- Source:
- Queryable.cs
- Source:
- Queryable.cs
Returns the minimum value of a generic IQueryable
public:
generic
[System::Runtime::CompilerServices::Extension]
static TSource Min(System::Linq::IQueryable ^ source);
public static TSource Min(this System.Linq.IQueryable source);
public static TSource? Min(this System.Linq.IQueryable source);
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Enumerating collections as IQueryable can require creating new generic types or methods, which requires creating code at runtime. This may not work when AOT compiling.")]
public static TSource? Min(this System.Linq.IQueryable source);
static member Min : System.Linq.IQueryable<'Source> -> 'Source
[]
static member Min : System.Linq.IQueryable<'Source> -> 'Source
Public Function Min(Of TSource) (source As IQueryable(Of TSource)) As TSource
Type Parameters
- TSource
The type of the elements of source.
Parameters
- source
-
IQueryable
A sequence of values to determine the minimum of.
Returns
The minimum value in the sequence.
- Attributes
Exceptions
source is null.
source contains no elements.
Examples
The following code example demonstrates how to use Min
double[] doubles = { 1.5E+104, 9E+103, -2E+103 };
double min = doubles.AsQueryable().Min();
Console.WriteLine("The smallest number is {0}.", min);
/*
This code produces the following output:
The smallest number is -2E+103.
*/
Dim doubles() As Double = {1.5E+104, 9.0E+103, -2.0E+103}
Dim min As Double = doubles.AsQueryable().Min()
MsgBox(String.Format("The smallest number is {0}.", min))
'This code produces the following output:
'The smallest number is -2E+103.
Remarks
The Minsource parameter.
The query behavior that occurs as a result of executing an expression tree that represents calling Minsource parameter. The expected behavior is that it returns the minimum value in source.