有什么意义? [英] Significance of AsEnumerable?

查看:121
本文介绍了有什么意义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

var query = 
    from dt1 in dtStudent.AsEnumerable()
    join dt2 in dtMarks.AsEnumerable()
        on dt1.Field<int>("StudentID")
        equals dt2.Field<int>("StudentID")
    select new StudentMark
    {
        StudentName = dt1.Field<string>("StudentName"),
        Mark = dt2.Field<int>("Mark")
    };

在上面的编码中,AsEnumerable的意义是什么?如果AsEnumerable在.NET Framework中不存在,那么开发人员执行上述任务的方法是什么?

In the above coding, what is the significance of AsEnumerable? if the AsEnumerable doesn't exist in .NET Framework, then what would be the approach of developers to perform the above the task?

推荐答案

假设我正确地解释了它,那就是调用 DataTableExtensions.AsEnumerable() .没有这个(或类似的东西),您就不能使用LINQ to Objects,因为DataTable不实现IEnumerable<T>,而不能实现IEnumerable.

Assuming I'm interpreting it correctly, it's calling DataTableExtensions.AsEnumerable(). Without that (or something similar), you can't use LINQ to Objects as DataTable doesn't implement IEnumerable<T>, only IEnumerable.

请注意,一种替代方法是使用Cast<DataRow>,但这会有所不同,因为直接在Cast中使用DataTableGetEnumerator,而我相信

Note that an alternative would be to use Cast<DataRow>, but that would be subtly different as that would use the DataTable's GetEnumerator directly within Cast, whereas I believe EnumerableRowCollection<TRow> does slightly more funky things with the data table. It's unlikely to show up any real changes, except possibly a slight performance difference.

这篇关于有什么意义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆