Queryable.Select 메서드

정의

시퀀스의 각 요소를 새 폼에 투영합니다.Projects each element of a sequence into a new form.

오버로드

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

요소의 인덱스를 통합하여 시퀀스의 각 요소를 새 폼에 투영합니다.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>>)

시퀀스의 각 요소를 새 폼에 투영합니다.Projects each element of a sequence into a new form.

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

요소의 인덱스를 통합하여 시퀀스의 각 요소를 새 폼에 투영합니다.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)

형식 매개 변수

TSource

source 요소의 형식입니다.The type of the elements of source.

TResult

selector에 지정된 함수가 반환하는 값의 형식입니다.The type of the value returned by the function represented by selector.

매개 변수

source
IQueryable<TSource>

계산할 값의 시퀀스입니다.A sequence of values to project.

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

각 요소에 적용할 프로젝션 함수입니다.A projection function to apply to each element.

반환

IQueryable<TResult>

해당 요소가 source의 각 요소에 대해 프로젝션 함수를 호출한 결과인 IQueryable<T>입니다.An IQueryable<T> whose elements are the result of invoking a projection function on each element of source.

예외

source 또는 selectornull인 경우source or selector is null.

예제

다음 코드 예제에서는를 사용 하 여 일련의 값을 프로젝션 하 Select<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,Int32,TResult>>) 고 프로젝션 된 폼에서 각 요소의 인덱스를 사용 하는 방법을 보여 줍니다.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 }

설명

이 메서드에 형식 인수가 형식 중 하나인 형식의 매개 변수가 하나 이상 있습니다 Expression<TDelegate> Func<T,TResult> .This method has at least one parameter of type Expression<TDelegate> whose type argument is one of the Func<T,TResult> types. 이러한 매개 변수는 람다 식을 전달할 수 있으며로 컴파일됩니다 Expression<TDelegate> .For these parameters, you can pass in a lambda expression and it will be compiled to an Expression<TDelegate>.

Select<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,Int32,TResult>>)메서드는 자신을 MethodCallExpression 생성 된 제네릭 메서드로 호출 하는을 생성 합니다 Select<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,Int32,TResult>>) .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. 그런 다음 MethodCallExpression CreateQuery(Expression) IQueryProvider Provider 매개 변수의 속성이 나타내는의 메서드에를 전달 합니다 source .It then passes the MethodCallExpression to the CreateQuery(Expression) method of the IQueryProvider represented by the Provider property of the source parameter.

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

시퀀스의 각 요소를 새 폼에 투영합니다.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)

형식 매개 변수

TSource

source 요소의 형식입니다.The type of the elements of source.

TResult

selector에 지정된 함수가 반환하는 값의 형식입니다.The type of the value returned by the function represented by selector.

매개 변수

source
IQueryable<TSource>

계산할 값의 시퀀스입니다.A sequence of values to project.

selector
Expression<Func<TSource,TResult>>

각 요소에 적용할 프로젝션 함수입니다.A projection function to apply to each element.

반환

IQueryable<TResult>

해당 요소가 source의 각 요소에 대해 프로젝션 함수를 호출한 결과인 IQueryable<T>입니다.An IQueryable<T> whose elements are the result of invoking a projection function on each element of source.

예외

source 또는 selectornull인 경우source or selector is null.

예제

다음 코드 예제에서는를 사용 하 여 일련의 값을 프로젝션 하는 방법을 보여 줍니다 Select<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,TResult>>) .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

설명

이 메서드에 형식 인수가 형식 중 하나인 형식의 매개 변수가 하나 이상 있습니다 Expression<TDelegate> Func<T,TResult> .This method has at least one parameter of type Expression<TDelegate> whose type argument is one of the Func<T,TResult> types. 이러한 매개 변수는 람다 식을 전달할 수 있으며로 컴파일됩니다 Expression<TDelegate> .For these parameters, you can pass in a lambda expression and it will be compiled to an Expression<TDelegate>.

Select<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,TResult>>)메서드는 자신을 MethodCallExpression 생성 된 제네릭 메서드로 호출 하는을 생성 합니다 Select<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,TResult>>) .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. 그런 다음 MethodCallExpression CreateQuery(Expression) IQueryProvider Provider 매개 변수의 속성이 나타내는의 메서드에를 전달 합니다 source .It then passes the MethodCallExpression to the CreateQuery(Expression) method of the IQueryProvider represented by the Provider property of the source parameter.

호출을 나타내는 식 트리를 실행 한 결과로 발생 하는 쿼리 동작은 Select<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,TResult>>) 매개 변수의 형식 구현에 따라 달라 집니다 source .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. 예상 되는 동작은 selector 의 각 요소에 대해를 호출 하 source 여 다른 폼으로 프로젝션 하는 것입니다.The expected behavior is that it invokes selector on each element of source to project it into a different form.

적용 대상