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();
相关推荐
淡海水20 分钟前
11-04-Unity-Span-foreach-LINQ的分配与热路径边界
unity·c#·linq·foreach·span
唐青枫14 小时前
对象到底住在哪里?C#.NET 托管堆从分配、GC 到内存排查
c#·.net
fogota16 小时前
Emoji与Segoe MDL2 Assets的比较
c#·wpf
灸木17 小时前
C# 多线程与异步
c#
鱼听禅21 小时前
C# 学习笔记-使用 类型化客户端搭建HTTP客户端服务
学习·http·c#·工厂方法模式
geovindu1 天前
CSharp:Condition Variable Pattern
后端·设计模式·c#·.net·.netcore·条件变量模式·同步型模式
淡海水1 天前
11-03-Unity-List-T-和Dictionary-TKey-TValue-的性能调优实战
算法·unity·c#·list·dictionary
fogota1 天前
C# 如何调用系统图标
c#·.net
△曉風殘月〆1 天前
.NET是什么?为什么要选择.NET?
c#·.net·.net core·clr
fogota1 天前
C# WPF 按钮加载字体图标 / 动物头像
c#·.net·wpf