Queryable.Min Método
Definición
Sobrecargas
Min<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,TResult>>) |
Invoca una función de proyección en cada elemento de una interfaz IQueryable<T> genérica y devuelve el valor mínimo resultante.Invokes a projection function on each element of a generic IQueryable<T> and returns the minimum resulting value. |
Min<TSource>(IQueryable<TSource>) |
Devuelve el valor mínimo de una interfaz IQueryable<T> genérica.Returns the minimum value of a generic IQueryable<T>. |
Min<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,TResult>>)
Invoca una función de proyección en cada elemento de una interfaz IQueryable<T> genérica y devuelve el valor mínimo resultante.Invokes a projection function on each element of a generic IQueryable<T> and returns the minimum resulting value.
public:
generic <typename TSource, typename TResult>
[System::Runtime::CompilerServices::Extension]
static TResult Min(System::Linq::IQueryable<TSource> ^ source, System::Linq::Expressions::Expression<Func<TSource, TResult> ^> ^ selector);
public static TResult Min<TSource,TResult> (this System.Linq.IQueryable<TSource> source, System.Linq.Expressions.Expression<Func<TSource,TResult>> selector);
public static TResult Min<TSource,TResult> (this System.Linq.IQueryable<TSource>? source, System.Linq.Expressions.Expression<Func<TSource,TResult>>? selector);
static member Min : System.Linq.IQueryable<'Source> * System.Linq.Expressions.Expression<Func<'Source, 'Result>> -> 'Result
<Extension()>
Public Function Min(Of TSource, TResult) (source As IQueryable(Of TSource), selector As Expression(Of Func(Of TSource, TResult))) As TResult
Parámetros de tipo
- TSource
Tipo de los elementos de source
.The type of the elements of source
.
- TResult
Tipo del valor devuelto por la función representada por selector
.The type of the value returned by the function represented by selector
.
Parámetros
- source
- IQueryable<TSource>
Secuencia de valores cuyo valor mínimo se va a determinar.A sequence of values to determine the minimum of.
- selector
- Expression<Func<TSource,TResult>>
Función de proyección que se va a aplicar a cada elemento.A projection function to apply to each element.
Devoluciones
- TResult
El valor mínimo de la secuencia.The minimum value in the sequence.
Excepciones
source
o selector
es null
.source
or selector
is null
.
Ejemplos
En el ejemplo de código siguiente se muestra cómo utilizar Min<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,TResult>>) para determinar el valor mínimo de una secuencia de valores proyectados.The following code example demonstrates how to use Min<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,TResult>>) 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 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.
Comentarios
Este método tiene al menos un parámetro de tipo Expression<TDelegate> cuyo argumento de tipo es uno de los Func<T,TResult> tipos.This method has at least one parameter of type Expression<TDelegate> whose type argument is one of the Func<T,TResult> types. Para estos parámetros, puede pasar una expresión lambda y se compilará en un Expression<TDelegate> .For these parameters, you can pass in a lambda expression and it will be compiled to an Expression<TDelegate>.
El Min<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,TResult>>) método genera un MethodCallExpression que representa la llamada a Min<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,TResult>>) sí mismo como un método genérico construido.The Min<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,TResult>>) method generates a MethodCallExpression that represents calling Min<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,TResult>>) itself as a constructed generic method. A continuación, pasa el MethodCallExpression al Execute<TResult>(Expression) método de IQueryProvider representado por la Provider propiedad del source
parámetro.It then passes the MethodCallExpression to the Execute<TResult>(Expression) method of the IQueryProvider represented by the Provider property of the source
parameter.
El comportamiento de la consulta que se produce como resultado de ejecutar un árbol de expresión que representa Min<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,TResult>>) la llamada depende de la implementación del tipo del source
parámetro.The query behavior that occurs as a result of executing an expression tree that represents calling Min<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,TResult>>) depends on the implementation of the type of the source
parameter. El comportamiento esperado es que invoca selector
en cada elemento de source
y devuelve el valor mínimo.The expected behavior is that it invokes selector
on each element in source
and returns the minimum value.
Se aplica a
Min<TSource>(IQueryable<TSource>)
Devuelve el valor mínimo de una interfaz IQueryable<T> genérica.Returns the minimum value of a generic IQueryable<T>.
public:
generic <typename TSource>
[System::Runtime::CompilerServices::Extension]
static TSource Min(System::Linq::IQueryable<TSource> ^ source);
public static TSource Min<TSource> (this System.Linq.IQueryable<TSource> source);
public static TSource Min<TSource> (this System.Linq.IQueryable<TSource>? source);
static member Min : System.Linq.IQueryable<'Source> -> 'Source
<Extension()>
Public Function Min(Of TSource) (source As IQueryable(Of TSource)) As TSource
Parámetros de tipo
- TSource
Tipo de los elementos de source
.The type of the elements of source
.
Parámetros
- source
- IQueryable<TSource>
Secuencia de valores cuyo valor mínimo se va a determinar.A sequence of values to determine the minimum of.
Devoluciones
- TSource
El valor mínimo de la secuencia.The minimum value in the sequence.
Excepciones
source
es null
.source
is null
.
Ejemplos
En el ejemplo de código siguiente se muestra cómo utilizar Min<TSource>(IQueryable<TSource>) para determinar el valor mínimo de una secuencia.The following code example demonstrates how to use Min<TSource>(IQueryable<TSource>) to determine the minimum value in a sequence.
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.
Comentarios
El Min<TSource>(IQueryable<TSource>) método genera un MethodCallExpression que representa la llamada a Min<TSource>(IQueryable<TSource>) sí mismo como un método genérico construido.The Min<TSource>(IQueryable<TSource>) method generates a MethodCallExpression that represents calling Min<TSource>(IQueryable<TSource>) itself as a constructed generic method. A continuación, pasa el MethodCallExpression al Execute<TResult>(Expression) método de IQueryProvider representado por la Provider propiedad del source
parámetro.It then passes the MethodCallExpression to the Execute<TResult>(Expression) method of the IQueryProvider represented by the Provider property of the source
parameter.
El comportamiento de la consulta que se produce como resultado de ejecutar un árbol de expresión que representa Min<TSource>(IQueryable<TSource>) la llamada depende de la implementación del tipo del source
parámetro.The query behavior that occurs as a result of executing an expression tree that represents calling Min<TSource>(IQueryable<TSource>) depends on the implementation of the type of the source
parameter. El comportamiento esperado es que devuelva el valor mínimo de source
.The expected behavior is that it returns the minimum value in source
.