.net - EnumerableRowCollection<TRow> 类的用途是什么?

标签 .net linq datatable

正如文档中所述 DataTable.AsEnumerable()

Returns an IEnumerable<T> object, where the generic parameter T is DataRow. This object can be used in a LINQ expression or method query.

但是AsEnumerable()的返回类型不只是一个 IEnumerable<DataRow>它也是一个 EnumerableRowCollection<DataRow>

为什么会有这种类型?它比说 DataTable.Rows.Cast<DataRow>() 有什么好处?它只提供一个 IEnumerable<DataRow>

最佳答案

来自 EnumerableRowCollection<TRow> 的页面那里 有几种扩展方法,它们专门接受并返回 EnumerableRowCollection<TRow>由此我假设有DataTable仅使用 IEnumerable<DataRow> 时无法使用这些方法的特定实现

我也找到了这个blog post哪个州

In order for LinqDataView to work without using IQueryable (which we didn’t want to do for performance reasons), we have to hold on to the implementation class. As long as are working with a EnumerableRowCollection instance instead of a “something” which implements IEnumerable we can capture each LINQ operator into a state bag which allows us to recreate the effects of the LINQ query in a DataView.

我原以为 LINQ-To-Objects 涵盖了 LINQ 与 IEnumerables 的任何使用以及任何其他意味着使用 IQueryables 的内容,但我想事实并非如此。 IQueryable<T>还实现了 IEnumerable<T>但它比 DataRowCollection<TRow> 有更多 IQueryable 特定扩展方法可用

关于.net - EnumerableRowCollection<TRow> 类的用途是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33654910/

相关文章:

c# - 要说自定义异常是可序列化的,最低要求是什么?

c# - 从基类接口(interface)覆盖子类中的属性

c# - 我如何在 C# 中获取当前日期?

c# - 将保存按钮绑定(bind)到 DataTable

.net - 如何在VB.net中将日期转换为格式化的字符串?

linq - F# 和 PLINQ 扩展方法

c# - 如何用linq获取相关数据?

c# - 在 View 中显示来自 ViewModel 的平均值

html - Bootstrap 数据表 - 具有相同宽度的行的不同单元格数

javascript - 如何使用 JSON 数组填充数据表?