Queryable.Select Queryable.Select Queryable.Select Queryable.Select Method

Definizione

Proietta ogni elemento di una sequenza in un nuovo form.Projects each element of a sequence into a new form.

Overload

Select<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,Int32,TResult>>) Select<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,Int32,TResult>>) Select<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,Int32,TResult>>) Select<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,Int32,TResult>>)

Proietta ogni elemento di una sequenza in un nuovo form incorporando l'indice dell'elemento.Projects each element of a sequence into a new form by incorporating the element's index.

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

Proietta ogni elemento di una sequenza in un nuovo form.Projects each element of a sequence into a new form.

Select<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,Int32,TResult>>) Select<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,Int32,TResult>>) Select<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,Int32,TResult>>) Select<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,Int32,TResult>>)

Proietta ogni elemento di una sequenza in un nuovo form incorporando l'indice dell'elemento.Projects each element of a sequence into a new form by incorporating the element's index.

public:
generic <typename TSource, typename TResult>
[System::Runtime::CompilerServices::Extension]
 static System::Linq::IQueryable<TResult> ^ Select(System::Linq::IQueryable<TSource> ^ source, System::Linq::Expressions::Expression<Func<TSource, int, TResult> ^> ^ selector);
public static System.Linq.IQueryable<TResult> Select<TSource,TResult> (this System.Linq.IQueryable<TSource> source, System.Linq.Expressions.Expression<Func<TSource,int,TResult>> selector);
static member Select : System.Linq.IQueryable<'Source> * System.Linq.Expressions.Expression<Func<'Source, int, 'Result>> -> System.Linq.IQueryable<'Result>
<Extension()>
Public Function Select(Of TSource, TResult) (source As IQueryable(Of TSource), selector As Expression(Of Func(Of TSource, Integer, TResult))) As IQueryable(Of 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>

Sequenza di valori da proiettare.A sequence of values to project.

selector
Expression<Func<TSource,Int32,TResult>>

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

Restituisce

IQueryable<TResult>

Un' IQueryable<T> cui elementi sono il risultato ottenuto richiamando una funzione di proiezione su ogni elemento di source.An IQueryable<T> whose elements are the result of invoking a projection function on each element of source.

Eccezioni

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

Esempi

Esempio di codice seguente viene illustrato come utilizzare Select<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,Int32,TResult>>) proiettare su una sequenza di valori e usare l'indice di ogni elemento nella maschera proiettata.The following code example demonstrates how to use Select<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,Int32,TResult>>) to project over a sequence of values and use the index of each element in the projected form.

string[] fruits = { "apple", "banana", "mango", "orange", 
                      "passionfruit", "grape" };

// Project an anonymous type that contains the
// index of the string in the source array, and
// a string that contains the same number of characters
// as the string's index in the source array.
var query =
    fruits.AsQueryable()
    .Select((fruit, index) =>
                new { index, str = fruit.Substring(0, index) });

foreach (var obj in query)
    Console.WriteLine("{0}", obj);

/*
    This code produces the following output:

    { index = 0, str =  }
    { index = 1, str = b }
    { index = 2, str = ma }
    { index = 3, str = ora }
    { index = 4, str = pass }
    { index = 5, str = grape }
*/

Dim fruits() As String = {"apple", "banana", "mango", "orange", _
                      "passionfruit", "grape"}

' Project an anonymous type that contains the
' index of the string in the source array, and
' a string that contains the same number of characters
' as the string's index in the source array.
Dim query = _
    fruits.AsQueryable() _
    .Select(Function(fruit, index) New With {index, .str = fruit.Substring(0, index)})

Dim output As New System.Text.StringBuilder
For Each obj In query
    output.AppendLine(obj.ToString())
Next

' Display the output.
MsgBox(output.ToString())

' This code produces the following output:

' { index = 0, str =  }
' { index = 1, str = b }
' { index = 2, str = ma }
' { index = 3, str = ora }
' { index = 4, str = pass }
' { index = 5, str = grape }

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 Select<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,Int32,TResult>>) metodo genera un MethodCallExpression che rappresenta una chiamata Select<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,Int32,TResult>>) stesso come un metodo generico costruito.The Select<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,Int32,TResult>>) method generates a MethodCallExpression that represents calling Select<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,Int32,TResult>>) itself as a constructed generic method. Passa quindi il MethodCallExpression per il CreateQuery(Expression) metodo del IQueryProvider rappresentato dal Provider proprietà del source parametro.It then passes the MethodCallExpression to the CreateQuery(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 Select<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,Int32,TResult>>) dipendono dall'implementazione del tipo del source parametro.The query behavior that occurs as a result of executing an expression tree that represents calling Select<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,Int32,TResult>>) depend on the implementation of the type of the source parameter. Il comportamento previsto è che richiami selector su ogni elemento di source per proiettarlo in un formato differente.The expected behavior is that it invokes selector on each element of source to project it into a different form.

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

Proietta ogni elemento di una sequenza in un nuovo form.Projects each element of a sequence into a new form.

public:
generic <typename TSource, typename TResult>
[System::Runtime::CompilerServices::Extension]
 static System::Linq::IQueryable<TResult> ^ Select(System::Linq::IQueryable<TSource> ^ source, System::Linq::Expressions::Expression<Func<TSource, TResult> ^> ^ selector);
public static System.Linq.IQueryable<TResult> Select<TSource,TResult> (this System.Linq.IQueryable<TSource> source, System.Linq.Expressions.Expression<Func<TSource,TResult>> selector);
static member Select : System.Linq.IQueryable<'Source> * System.Linq.Expressions.Expression<Func<'Source, 'Result>> -> System.Linq.IQueryable<'Result>
<Extension()>
Public Function Select(Of TSource, TResult) (source As IQueryable(Of TSource), selector As Expression(Of Func(Of TSource, TResult))) As IQueryable(Of 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>

Sequenza di valori da proiettare.A sequence of values to project.

selector
Expression<Func<TSource,TResult>>

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

Restituisce

IQueryable<TResult>

Un' IQueryable<T> cui elementi sono il risultato ottenuto richiamando una funzione di proiezione su ogni elemento di source.An IQueryable<T> whose elements are the result of invoking a projection function on each element of source.

Eccezioni

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

Esempi

Esempio di codice seguente viene illustrato come utilizzare Select<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,TResult>>) al progetto in base a una sequenza di valori.The following code example demonstrates how to use Select<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,TResult>>) to project over a sequence of values.

List<int> range =
    new List<int> { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

// Project the square of each int value.
IEnumerable<int> squares =
    range.AsQueryable().Select(x => x * x);

foreach (int num in squares)
    Console.WriteLine(num);

/*
    This code produces the following output:

    1
    4
    9
    16
    25
    36
    49
    64
    81
    100
*/

Dim range As New List(Of Integer)(New Integer() {1, 2, 3, 4, 5, 6, 7, 8, 9, 10})

' Project the square of each int value.
Dim squares As IEnumerable(Of Integer) = _
    range.AsQueryable().Select(Function(x) x * x)

Dim output As New System.Text.StringBuilder
For Each num As Integer In squares
    output.AppendLine(num)
Next

' Display the output.
MsgBox(output.ToString())

' This code produces the following output:

' 1
' 4
' 9
' 16
' 25
' 36
' 49
' 64
' 81
' 100

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 Select<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,TResult>>) metodo genera un MethodCallExpression che rappresenta una chiamata Select<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,TResult>>) stesso come un metodo generico costruito.The Select<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,TResult>>) method generates a MethodCallExpression that represents calling Select<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,TResult>>) itself as a constructed generic method. Passa quindi il MethodCallExpression per il CreateQuery(Expression) metodo del IQueryProvider rappresentato dal Provider proprietà del source parametro.It then passes the MethodCallExpression to the CreateQuery(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 Select<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 Select<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 di source per proiettarlo in un formato differente.The expected behavior is that it invokes selector on each element of source to project it into a different form.

Si applica a