Queryable.Select 메서드

정의

시퀀스의 각 요소를 새 폼에 투영합니다.

오버로드

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

요소의 인덱스를 통합하여 시퀀스의 각 요소를 새 폼에 투영합니다.

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

시퀀스의 각 요소를 새 폼에 투영합니다.

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

Source:
Queryable.cs
Source:
Queryable.cs
Source:
Queryable.cs

요소의 인덱스를 통합하여 시퀀스의 각 요소를 새 폼에 투영합니다.

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)

형식 매개 변수

TSource

source 요소의 형식입니다.

TResult

selector에 지정된 함수가 반환하는 값의 형식입니다.

매개 변수

source
IQueryable<TSource>

계산할 값의 시퀀스입니다.

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

각 요소에 적용할 프로젝션 함수입니다.

반환

IQueryable<TResult>

해당 요소가 source의 각 요소에 대해 프로젝션 함수를 호출한 결과인 IQueryable<T>입니다.

예외

source 또는 selectornull인 경우

예제

다음 코드 예제에서는 를 사용하여 Select<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,Int32,TResult>>) 값 시퀀스를 프로젝션하고 프로젝션된 형식의 각 요소의 인덱스를 사용하는 방법을 보여 줍니다.

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 }

설명

이 메서드에는 형식 인수가 형식 중 하나인 형식 Expression<TDelegate> 의 매개 변수가 Func<T,TResult> 하나 이상 있습니다. 이러한 매개 변수의 경우 람다 식을 전달할 수 있으며 로 컴파일됩니다 Expression<TDelegate>.

메서드는 Select<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,Int32,TResult>>)MethodCallExpression 생성된 제네릭 메서드로 자신을 호출 Select<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,Int32,TResult>>) 하는 을 생성합니다. 그런 다음 을 MethodCallExpression 매개 변수의 CreateQuery(Expression) 속성으로 나타내는 ProviderIQueryProvider 메서드에 source 전달합니다.

호출 Select<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,Int32,TResult>>) 을 나타내는 식 트리를 실행한 결과로 발생하는 쿼리 동작은 매개 변수 형식 source 의 구현에 따라 달라집니다. 예상되는 동작은 의 source 각 요소에서 를 호출 selector 하여 다른 형식으로 프로젝션하는 것입니다.

적용 대상

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

Source:
Queryable.cs
Source:
Queryable.cs
Source:
Queryable.cs

시퀀스의 각 요소를 새 폼에 투영합니다.

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)

형식 매개 변수

TSource

source 요소의 형식입니다.

TResult

selector에 지정된 함수가 반환하는 값의 형식입니다.

매개 변수

source
IQueryable<TSource>

계산할 값의 시퀀스입니다.

selector
Expression<Func<TSource,TResult>>

각 요소에 적용할 프로젝션 함수입니다.

반환

IQueryable<TResult>

해당 요소가 source의 각 요소에 대해 프로젝션 함수를 호출한 결과인 IQueryable<T>입니다.

예외

source 또는 selectornull인 경우

예제

다음 코드 예제에서는 를 사용하여 Select<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,TResult>>) 값 시퀀스를 프로젝스하는 방법을 보여 줍니다.

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

설명

이 메서드에는 형식 인수가 형식 중 하나인 형식 Expression<TDelegate> 의 매개 변수가 Func<T,TResult> 하나 이상 있습니다. 이러한 매개 변수의 경우 람다 식을 전달할 수 있으며 로 컴파일됩니다 Expression<TDelegate>.

메서드는 Select<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,TResult>>)MethodCallExpression 생성된 제네릭 메서드로 자신을 호출 Select<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,TResult>>) 하는 을 생성합니다. 그런 다음 을 MethodCallExpression 매개 변수의 CreateQuery(Expression) 속성으로 나타내는 ProviderIQueryProvider 메서드에 source 전달합니다.

호출 Select<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,TResult>>) 을 나타내는 식 트리를 실행한 결과로 발생하는 쿼리 동작은 매개 변수 형식 source 의 구현에 따라 달라집니다. 예상되는 동작은 의 source 각 요소에서 를 호출 selector 하여 다른 형식으로 프로젝션하는 것입니다.

적용 대상