Enumerable.AsEnumerable(IEnumerable<TSource>) Enumerable.AsEnumerable(IEnumerable<TSource>) Enumerable.AsEnumerable(IEnumerable<TSource>) Enumerable.AsEnumerable(IEnumerable<TSource>) Method

정의

IEnumerable<T>로 형식화된 입력을 반환합니다.Returns the input typed as IEnumerable<T>.

public:
generic <typename TSource>
[System::Runtime::CompilerServices::Extension]
 static System::Collections::Generic::IEnumerable<TSource> ^ AsEnumerable(System::Collections::Generic::IEnumerable<TSource> ^ source);
public static System.Collections.Generic.IEnumerable<TSource> AsEnumerable<TSource> (this System.Collections.Generic.IEnumerable<TSource> source);
static member AsEnumerable : seq<'Source> -> seq<'Source>
<Extension()>
Public Function AsEnumerable(Of TSource) (source As IEnumerable(Of TSource)) As IEnumerable(Of TSource)

형식 매개 변수

TSource

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

매개 변수

source
IEnumerable<TSource>

로 형식화할 시퀀스 IEnumerable<T>합니다.The sequence to type as IEnumerable<T>.

반환

IEnumerable<TSource>

로 형식화 된 입력된 시퀀스 IEnumerable<T>합니다.The input sequence typed as IEnumerable<T>.

예제

다음 코드 예제에 사용 하는 방법을 보여 줍니다 AsEnumerable<TSource>(IEnumerable<TSource>) 형식을 숨기려면의 사용자 지정 Where 메서드는 표준 쿼리 연산자 구현이 필요한 경우.The following code example demonstrates how to use AsEnumerable<TSource>(IEnumerable<TSource>) to hide a type's custom Where method when the standard query operator implementation is desired.

// Custom class.
class Clump<T> : List<T>
{
    // Custom implementation of Where().
    public IEnumerable<T> Where(Func<T, bool> predicate)
    {
        Console.WriteLine("In Clump's implementation of Where().");
        return Enumerable.Where(this, predicate);
    }
}

static void AsEnumerableEx1()
{
    // Create a new Clump<T> object.
    Clump<string> fruitClump =
        new Clump<string> { "apple", "passionfruit", "banana", 
            "mango", "orange", "blueberry", "grape", "strawberry" };

    // First call to Where():
    // Call Clump's Where() method with a predicate.
    IEnumerable<string> query1 =
        fruitClump.Where(fruit => fruit.Contains("o"));

    Console.WriteLine("query1 has been created.\n");

    // Second call to Where():
    // First call AsEnumerable() to hide Clump's Where() method and thereby
    // force System.Linq.Enumerable's Where() method to be called.
    IEnumerable<string> query2 =
        fruitClump.AsEnumerable().Where(fruit => fruit.Contains("o"));

    // Display the output.
    Console.WriteLine("query2 has been created.");
}

// This code produces the following output:
//
// In Clump's implementation of Where().
// query1 has been created.
//
// query2 has been created.
Dim output As New System.Text.StringBuilder

' A custom class.
Class Clump(Of T)
    Inherits List(Of T)

    ' Constructor.
    Public Sub New(ByVal collection As IEnumerable(Of T))
        MyBase.New(collection)
    End Sub

    ' Custom implementation of Where().
    Function Where(ByVal predicate As Func(Of T, Boolean)) As IEnumerable(Of T)
        output.AppendLine("In Clump's implementation of Where().")
        Return Enumerable.Where(Me, predicate)
    End Function
End Class

Sub AsEnumerableEx1()
    ' Create a new Clump(Of T) object.
    Dim fruitClump As New Clump(Of String)(New String() _
                                       {"apple", "passionfruit", "banana",
                                        "mango", "orange", "blueberry",
                                        "grape", "strawberry"})

    ' First call to Where():
    ' Call Clump's Where() method with a predicate.
    Dim query1 As IEnumerable(Of String) =
    fruitClump.Where(Function(fruit) fruit.Contains("o"))
    output.AppendLine("query1 has been created." & vbCrLf)

    ' Second call to Where():
    ' First call AsEnumerable() to hide Clump's Where() method and thereby
    ' force System.Linq.Enumerable's Where() method to be called.
    Dim query2 As IEnumerable(Of String) =
    fruitClump.AsEnumerable().Where(Function(fruit) fruit.Contains("o"))
    output.AppendLine("query2 has been created.")

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

' This code produces the following output:
'
' In Clump's implementation of Where().
' query1 has been created.
'
' query2 has been created.

설명

합니다 AsEnumerable<TSource>(IEnumerable<TSource>) 메서드는 어떠한 영향도 이외의의 컴파일 타임 형식 변경 source 구현 하는 형식에서 IEnumerable<T>IEnumerable<T> 자체입니다.The AsEnumerable<TSource>(IEnumerable<TSource>) method has no effect other than to change the compile-time type of source from a type that implements IEnumerable<T> to IEnumerable<T> itself.

AsEnumerable<TSource>(IEnumerable<TSource>) 시퀀스를 구현 하는 경우 쿼리 구현 중에서 선택할 수 있습니다 IEnumerable<T> 에 다양 한 공용 쿼리 메서드를 사용할 수 있습니다.AsEnumerable<TSource>(IEnumerable<TSource>) can be used to choose between query implementations when a sequence implements IEnumerable<T> but also has a different set of public query methods available. 예를 들어 제네릭 클래스가 있다고 가정 Table 구현 하는 IEnumerable<T> 와 같은 메서드가 자체 및 Where, Select, 및 SelectMany, 호출 Where 공용 호출 Where 메서드의Table.For example, given a generic class Table that implements IEnumerable<T> and has its own methods such as Where, Select, and SelectMany, a call to Where would invoke the public Where method of Table. A Table 데이터베이스 테이블을 나타내는 형식에 있을 수는 Where 식 트리로 조건자 인수 및 원격 실행에 대 한 트리를 SQL로 변환 하는 메서드.A Table type that represents a database table could have a Where method that takes the predicate argument as an expression tree and converts the tree to SQL for remote execution. 원격 실행 좋지 않으면, 예를 들어 조건자에는 로컬 메서드를 호출 하므로 AsEnumerable 사용자 지정 메서드를 숨기고 대신 표준 쿼리 연산자를 사용할 수 있도록 메서드를 사용할 수 있습니다.If remote execution is not desired, for example because the predicate invokes a local method, the AsEnumerable method can be used to hide the custom methods and instead make the standard query operators available.

적용 대상