Querying DataColumnCollection with LINQ

别来无恙 提交于 2019-12-02 16:28:27

How about:

var x = from c in dt.Columns.Cast<DataColumn>()
        select c.ColumnName;

You could also use:

var x = from DataColumn c in myDataTable.Columns
        select c.ColumnName

It will effectively do the same as Dave's code: "in a query expression, an explicitly typed iteration variable translates to an invocation of Cast(IEnumerable)", according to the Enumerable.Cast<TResult> Method MSDN article.

With Linq Method Syntax:

var x = myDataTable.Columns.Cast<DataColumn>().Select(c => c.ColumnName);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!