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();
相关推荐
程序leo源2 小时前
Qt信号与槽深度详解
c语言·开发语言·数据库·c++·qt·c#
yoyo_zzm7 小时前
四大编程语言对比:C/C++/C#/PHP
c++·c#·php
weixin_428005308 小时前
C#调用 AI学习从0开始-第1阶段(基础与工具)-第4天CoT思维链学习
开发语言·学习·ai·c#·cot
政沅同学8 小时前
C# TCP通讯(客户端)
网络·tcp/ip·c#
思麟呀8 小时前
在C++基础上理解CSharp-3
开发语言·c++·c#
rockey62720 小时前
AScript如何实现LINQ语法
sql·c#·.net·linq·script·eval·expression
xiaoshuaishuai820 小时前
C# CDN加速与离线包优化PowerSetting慢问题
开发语言·windows·spring·c#
烈焰猩猩1 天前
【无标题】
c#
njsgcs1 天前
制作solidworks插件 装配体导出展开耗时分析
开发语言·c#·solidworks
njsgcs1 天前
c# solidworks 标注攻牙
开发语言·c#·solidworks