DataTableExtensions::AsEnumerable Method
Returns an IEnumerable<T> object, where the generic parameter T is DataRow. This object can be used in a LINQ expression or method query.
Assembly: System.Data.DataSetExtensions (in System.Data.DataSetExtensions.dll)
[ExtensionAttribute] public: static EnumerableRowCollection<DataRow^>^ AsEnumerable( DataTable^ source )
Parameters
- source
- Type: System.Data::DataTable
The source DataTable to make enumerable.
Return Value
Type: System.Data::EnumerableRowCollection<DataRow>An IEnumerable<T> object, where the generic parameter T is DataRow.
Usage Note
In Visual Basic and C#, you can call this method as an instance method on any object of type DataTable. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).| Exception | Condition |
|---|---|
| ArgumentNullException | The source DataTable is nullptr. |
Language-Integrated Query (LINQ) queries work on data sources that implement the IEnumerable<T> interface or the IQueryable interface. The DataTable class does not implement either interface, so you must call the AsEnumerable method to use the DataTable as a source in the From clause of a LINQ query. You can also obtain custom, domain-specific operators, such as CopyToDataTable, by returning an IEnumerable<T> object.
The enumerable object returned by the AsEnumerable method is permanently bound to the DataTable that produced it. Multiple calls to the AsEnumerable method will return multiple, independent queryable objects that are all bound to the source DataTable.
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.