Freigeben über


Queryable.AsQueryable Method (IEnumerable)

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Converts an IEnumerable to an IQueryable.

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

Syntax

'Declaration
<ExtensionAttribute> _
Public Shared Function AsQueryable ( _
    source As IEnumerable _
) As IQueryable
public static IQueryable AsQueryable(
    this IEnumerable source
)

Parameters

Return Value

Type: System.Linq.IQueryable
An IQueryable that represents the input sequence.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type IEnumerable. When you use instance method syntax to call this method, omit the first parameter.

Exceptions

Exception Condition
ArgumentException

source does not implement IEnumerable<T> for some T.

ArgumentNullException

source is nulla null reference (Nothing in Visual Basic).

Remarks

If the type of source implements IQueryable<T>, AsQueryable(IEnumerable) returns it directly. Otherwise, it returns an IQueryable<T> that executes queries by calling the equivalent query operator methods in Enumerable instead of those in Queryable.

This method assumes that source implements IEnumerable<T> for some T. At runtime, the result is of type IQueryable<T> for the same T. This method is useful in dynamic scenarios when you do not statically know the type of T.

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.