Queryable.Min Queryable.Min Queryable.Min Queryable.Min Method

Definizione

Overload

Min<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,TResult>>) Min<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,TResult>>) Min<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,TResult>>) Min<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,TResult>>)

Richiama una funzione di proiezione su ogni elemento di un oggetto generico IQueryable<T> e restituisce il valore minimo risultante.Invokes a projection function on each element of a generic IQueryable<T> and returns the minimum resulting value.

Min<TSource>(IQueryable<TSource>) Min<TSource>(IQueryable<TSource>) Min<TSource>(IQueryable<TSource>) Min<TSource>(IQueryable<TSource>)

Restituisce il valore minimo di un oggetto generico IQueryable<T>.Returns the minimum value of a generic IQueryable<T>.

Min<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,TResult>>) Min<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,TResult>>) Min<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,TResult>>) Min<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,TResult>>)

Richiama una funzione di proiezione su ogni elemento di un oggetto generico IQueryable<T> e restituisce il valore minimo risultante.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);
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

Parametri di tipo

TSource

Tipo degli elementi di source.The type of the elements of source.

TResult

Il tipo del valore restituito dalla funzione rappresentata da selector.The type of the value returned by the function represented by selector.

Parametri

source
IQueryable<TSource>

Una sequenza di valori per determinare il valore minimo di.A sequence of values to determine the minimum of.

selector
Expression<Func<TSource,TResult>>

Una funzione di proiezione da applicare a ogni elemento.A projection function to apply to each element.

Restituisce

TResult TResult TResult TResult

Valore minimo della sequenza.The minimum value in the sequence.

Eccezioni

source o selector è null.source or selector is null.

Esempi

Esempio di codice seguente viene illustrato come utilizzare Min<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,TResult>>) per determinare il valore minimo in una sequenza di valori proiettati.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.  

Commenti

Questo metodo ha almeno un parametro di tipo Expression<TDelegate> il cui argomento tipo è uno del Func<T,TResult> tipi.This method has at least one parameter of type Expression<TDelegate> whose type argument is one of the Func<T,TResult> types. Per questi parametri, è possibile passare in un'espressione lambda e verrà compilata per un Expression<TDelegate>.For these parameters, you can pass in a lambda expression and it will be compiled to an Expression<TDelegate>.

Il Min<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,TResult>>) metodo genera un MethodCallExpression che rappresenta una chiamata Min<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,TResult>>) stesso come un metodo generico costruito.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. Passa quindi il MethodCallExpression per il Execute<TResult>(Expression) metodo del IQueryProvider rappresentato dal Provider proprietà del source parametro.It then passes the MethodCallExpression to the Execute<TResult>(Expression) method of the IQueryProvider represented by the Provider property of the source parameter.

Il comportamento delle query che si verifica in seguito all'esecuzione di un albero delle espressioni che rappresenta una chiamata Min<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,TResult>>) dipende dall'implementazione del tipo del source parametro.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. Il comportamento previsto è che richiami selector su ogni elemento in source e restituisce il valore minimo.The expected behavior is that it invokes selector on each element in source and returns the minimum value.

Min<TSource>(IQueryable<TSource>) Min<TSource>(IQueryable<TSource>) Min<TSource>(IQueryable<TSource>) Min<TSource>(IQueryable<TSource>)

Restituisce il valore minimo di un oggetto generico IQueryable<T>.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);
static member Min : System.Linq.IQueryable<'Source> -> 'Source
<Extension()>
Public Function Min(Of TSource) (source As IQueryable(Of TSource)) As TSource

Parametri di tipo

TSource

Tipo degli elementi di source.The type of the elements of source.

Parametri

source
IQueryable<TSource>

Una sequenza di valori per determinare il valore minimo di.A sequence of values to determine the minimum of.

Restituisce

TSource TSource TSource TSource

Valore minimo della sequenza.The minimum value in the sequence.

Eccezioni

Esempi

Esempio di codice seguente viene illustrato come utilizzare Min<TSource>(IQueryable<TSource>) per determinare il valore minimo in una sequenza.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.

Commenti

Il Min<TSource>(IQueryable<TSource>) metodo genera un MethodCallExpression che rappresenta una chiamata Min<TSource>(IQueryable<TSource>) stesso come un metodo generico costruito.The Min<TSource>(IQueryable<TSource>) method generates a MethodCallExpression that represents calling Min<TSource>(IQueryable<TSource>) itself as a constructed generic method. Passa quindi il MethodCallExpression per il Execute<TResult>(Expression) metodo del IQueryProvider rappresentato dal Provider proprietà del source parametro.It then passes the MethodCallExpression to the Execute<TResult>(Expression) method of the IQueryProvider represented by the Provider property of the source parameter.

Il comportamento delle query che si verifica in seguito all'esecuzione di un albero delle espressioni che rappresenta una chiamata Min<TSource>(IQueryable<TSource>) dipende dall'implementazione del tipo del source parametro.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. Il comportamento previsto è che restituisce il valore minimo in source.The expected behavior is that it returns the minimum value in source.

Si applica a