Queryable.Cast<TResult>(IQueryable) 메서드


IQueryable의 요소를 지정된 형식으로 변환합니다.Converts the elements of an IQueryable to the specified type.

generic <typename TResult>
 static System::Linq::IQueryable<TResult> ^ Cast(System::Linq::IQueryable ^ source);
public static System.Linq.IQueryable<TResult> Cast<TResult> (this System.Linq.IQueryable source);
static member Cast : System.Linq.IQueryable -> System.Linq.IQueryable<'Result>
Public Function Cast(Of TResult) (source As IQueryable) As IQueryable(Of TResult)

형식 매개 변수


source의 요소를 변환할 형식입니다.The type to convert the elements of source to.

매개 변수


변환할 요소가 들어 있는 IQueryable입니다.The IQueryable that contains the elements to be converted.



지정된 형식으로 변환되는 소스 시퀀스의 각 요소가 들어 있는 IQueryable<T>입니다.An IQueryable<T> that contains each element of the source sequence converted to the specified type.


sourcenull인 경우source is null.

시퀀스의 요소를 TResult 형식으로 캐스팅할 수 없는 경우An element in the sequence cannot be cast to type TResult.


다음 코드 예제에 사용 하는 방법을 보여 줍니다 Cast<TResult>(IQueryable) 입력 시퀀스의 개체를 변환할 String합니다.The following code example demonstrates how to use Cast<TResult>(IQueryable) to convert objects in a sequence to type String.

// Create a list of objects.
List<object> words =
    new List<object> { "green", "blue", "violet" };

// Cast the objects in the list to type 'string'
// and project the first letter of each string.
IEnumerable<string> query =
    .Select(str => str.Substring(0, 1));

foreach (string s in query)

/*  This code produces the following output:


' Create a list of objects.
Dim words As New List(Of Object)(New Object() {"green", "blue", "violet"})

' Cast the objects in the list to type 'string'
' and project the first letter of each string.
Dim query As IEnumerable(Of String) = _
    words.AsQueryable() _
            .Cast(Of String)() _
            .Select(Function(str) str.Substring(0, 1))

For Each s As String In query

' This code produces the following output:
' g
' b
' v


Cast<TResult>(IQueryable) 메서드를 생성 한 MethodCallExpression 호출을 나타내는 Cast<TResult>(IQueryable) 로 생성된 된 제네릭 메서드 자체.The Cast<TResult>(IQueryable) method generates a MethodCallExpression that represents calling Cast<TResult>(IQueryable) itself as a constructed generic method. 그런 다음 전달를 MethodCallExpressionCreateQuery(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.

호출을 나타내는 식 트리를 실행 한 결과로 발생 하는 쿼리 동작 Cast<TResult>(IQueryable) 형식의 구현에 따라는 source 매개 변수입니다.The query behavior that occurs as a result of executing an expression tree that represents calling Cast<TResult>(IQueryable) depends on the implementation of the type of the source parameter. 예상 되는 동작의 값을 변환 하는 것은 source 형식으로 TResult입니다.The expected behavior is that it converts the values in source to type TResult.

적용 대상