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


The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Returns the input typed as IEnumerable<'T>.

Namespace:   System.Linq
Assembly:  System.Core (in System.Core.dll)

static member AsEnumerable<'TSource> : 
        source:IEnumerable<'TSource> -> IEnumerable<'TSource>


Type: System.Collections.Generic.IEnumerable<'TSource>

The sequence to type as IEnumerable<'T>.

Return Value

Type: System.Collections.Generic.IEnumerable<'TSource>

The input sequence typed as IEnumerable<'T>.

Type Parameters


The type of the elements of source.

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>) 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. 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 type that represents a database table could have a Wheremethod that takes the predicate argument as an expression tree and converts the tree to SQL for remote execution. If remote execution is not desired, for example because the predicate invokes a local method, the AsEnumerable<'TSource> method can be used to hide the custom methods and instead make the standard query operators available.

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.

No code example is currently available or this language may not be supported.

Universal Windows Platform
Available since 8
.NET Framework
Available since 3.5
Portable Class Library
Supported in: portable .NET platforms
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top