LINQ-123 题外篇之IEnumerable和IQueryable

这两天又学习了2篇,记录下:

IEnumerable and IQueryable in C# - Dot Net Tutorials

Differences Between IEnumerable and IQueryable in C# - Dot Net Tutorials

实现接口IEnumerable和IQueryable是使用LINQ查询的必要条件。

关于 IEnumerable<T>IQueryable<T>

关于接口的定义,可以在链接的网页看到。然后会发现其实IQueryable<T>"继承"了IEnumerable<T>,细节方面参考上面的几个页面

简单的概括下:

1、IEnumerable<T>在查询端进行过滤等处理,服务端(数据源方)只负责返回数据。主要用于在内存中执行各种操作,适合小数据。IQueryable<T>服务端执行过滤处理,主要用于远程服务查询,适合大量数据的查询等操作。

2、IEnumerable<T>可以转换为IQueryable<T>

复制代码
 var students = new List<Student>(){
            new Student{
                Age=20,
                Name="李明",
                Gender=Gender.Male
            },
            new Student{
                Age=21,
                Name="赵雷",
                Gender=Gender.Male
            },
            new Student{
                Age=20,
                Name="韩小梅",
                Gender=Gender.Female
            },
            new Student{
                Age=19,
                Name="王蕾",
                Gender=Gender.Female
            },

        };
        var queryableStu=students.AsQueryable();
相关推荐
吴可可1232 小时前
C# CAD二次开发:合并首尾重合多段线
c#
EIP低代码平台3 小时前
EIP低代码平台 - 应用管理 - 表单设计
低代码·c#·权限·工作流·netcore
czhc11400756633 小时前
726:zoffset
c#
向夏威夷 梦断明暄6 小时前
C# 弃元模式:从语法糖到性能利器的深度解析
服务器·数据库·c#
rick9777 小时前
C# × Python 互操不再难:DotNetPy 让两大生态真正融合
c#
ellis19708 小时前
C#/Unity清理非托管资源
unity·c#
吴可可12321 小时前
C#用OpenCVSharp提取轮廓生成CAD多段线
c#
玖玥拾1 天前
Unity 3D 笔记(十四)Unity/C# Socket 网络笔记3
服务器·网络·unity·c#
玖玥拾1 天前
Unity 3D 笔记(十七)Unity/C# Socket 网络笔记6
服务器·网络·unity·c#
geovindu1 天前
CSharp: Iterative Algorithms
开发语言·后端·算法·c#·.net·迭代算法