Queryable.Select Yöntem

Tanım

Bir dizinin her öğesini yeni bir forma projeler.

Aşırı Yüklemeler

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

Öğenin dizinini birleştirerek bir dizinin her öğesini yeni bir forma projeler.

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

Bir dizinin her öğesini yeni bir forma projeler.

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

Kaynak:
Queryable.cs
Kaynak:
Queryable.cs
Kaynak:
Queryable.cs

Öğenin dizinini birleştirerek bir dizinin her öğesini yeni bir forma projeler.

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)

Tür Parametreleri

TSource

öğelerinin sourcetürü.

TResult

işlevi tarafından döndürülen değerin türü.selector

Parametreler

source
IQueryable<TSource>

Yansıtacak değer dizisi.

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

Her öğeye uygulanacak projeksiyon işlevi.

Döndürülenler

IQueryable<TResult>

IQueryable<T> öğeleri, her öğesinde bir projeksiyon işlevini çağırmanın sonucudursource.

Özel durumlar

source veya selector şeklindedir null.

Örnekler

Aşağıdaki kod örneği, bir dizi değer üzerinde yansıtma yapmak ve öngörülen formdaki her öğenin dizinini kullanmak için komutunun nasıl Select<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,Int32,TResult>>) kullanılacağını gösterir.

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 }

Açıklamalar

Bu yöntem, tür bağımsız değişkeni türlerden Expression<TDelegate> biri olan türünde en az bir parametreye Func<T,TResult> sahiptir. Bu parametreler için bir lambda ifadesi geçirebilirsiniz ve bu ifade bir Expression<TDelegate>olarak derlenir.

yöntemi, Select<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,Int32,TResult>>) kendisini oluşturulan genel bir MethodCallExpression yöntem olarak çağıran Select<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,Int32,TResult>>) bir oluşturur. Ardından parametresinin MethodCallExpressionCreateQuery(Expression) özelliği tarafından temsil edilen yöntemine IQueryProviderProvidersource iletir.

Çağrıyı Select<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,Int32,TResult>>) temsil eden bir ifade ağacının yürütülmesi sonucunda oluşan sorgu davranışı, parametre türünün uygulanmasına source bağlıdır. Beklenen davranış, öğesinin her öğesinde source çağırarak selector farklı bir forma yansıtmasıdır.

Şunlara uygulanır

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

Kaynak:
Queryable.cs
Kaynak:
Queryable.cs
Kaynak:
Queryable.cs

Bir dizinin her öğesini yeni bir forma projeler.

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)

Tür Parametreleri

TSource

öğelerinin sourcetürü.

TResult

işlevi tarafından döndürülen değerin türü.selector

Parametreler

source
IQueryable<TSource>

Yansıtacak değer dizisi.

selector
Expression<Func<TSource,TResult>>

Her öğeye uygulanacak projeksiyon işlevi.

Döndürülenler

IQueryable<TResult>

IQueryable<T> öğeleri, her öğesinde bir projeksiyon işlevini çağırmanın sonucudursource.

Özel durumlar

source veya selector şeklindedir null.

Örnekler

Aşağıdaki kod örneği, bir değer dizisi üzerinde yansıtmak için nasıl kullanılacağını Select<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,TResult>>) gösterir.

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

Açıklamalar

Bu yöntem, tür bağımsız değişkeni türlerden Expression<TDelegate> biri olan türünde en az bir parametreye Func<T,TResult> sahiptir. Bu parametreler için bir lambda ifadesi geçirebilirsiniz ve bu ifade bir Expression<TDelegate>olarak derlenir.

yöntemi, Select<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,TResult>>) kendisini oluşturulan genel bir MethodCallExpression yöntem olarak çağıran Select<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,TResult>>) bir oluşturur. Ardından parametresinin MethodCallExpressionCreateQuery(Expression) özelliği tarafından temsil edilen yöntemine IQueryProviderProvidersource iletir.

Çağrıyı Select<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,TResult>>) temsil eden bir ifade ağacının yürütülmesi sonucunda oluşan sorgu davranışı, parametre türünün uygulanmasına source bağlıdır. Beklenen davranış, öğesinin her öğesinde source çağırarak selector farklı bir forma yansıtmasıdır.

Şunlara uygulanır