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();
相关推荐
Kookoos15 分钟前
Redis + ABP vNext 构建分布式高可用缓存架构
redis·分布式·缓存·架构·c#·.net
Zhen (Evan) Wang2 小时前
ABP-Book Store Application中文讲解 - Part 2: The Book List Page
c#
小乖兽技术4 小时前
在 .NET 8 开发的WinForms 程序中展示程序版本号的几种方式
开发语言·c#·.net
TheWindofFate4 小时前
C# 基础 try-catch代码块
c#·try-catch
TIF星空8 小时前
【使用 C# 获取 USB 设备信息及进行通信】
开发语言·经验分享·笔记·学习·microsoft·c#
csdn_aspnet10 小时前
如何在 C# 中自定义 Datagridview 标题
c#·winform·datagridview
津津有味道10 小时前
MIFARE DESFire Light 卡C#读写更改卡片密钥源码
c#·light·desfire·ev2
炯哈哈13 小时前
【上位机——WPF】Window标签常用属性
开发语言·c#·wpf·上位机
江沉晚呤时19 小时前
C# 实现雪花算法(Snowflake Algorithm)详解与应用
c#·.net
酷炫码神1 天前
C#语法基础
开发语言·c#