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();
相关推荐
ajassi20003 小时前
开源 C# 快速开发(十七)进程--消息队列MSMQ
windows·开源·c#
葡萄城技术团队8 小时前
C# SIMD向量索引实战:从理论到高性能实现
c#
c#上位机9 小时前
wpf之TabControl
c#·wpf
玩泥巴的10 小时前
打造.NET平台的Lombok:实现构造函数注入、日志注入、构造者模式代码生成等功能
c#·.net·代码生成·roslyn
张人玉18 小时前
C# TCP 客户端开发笔记(TcpClient)
笔记·tcp/ip·c#
张人玉21 小时前
C# 通讯关键类的API
开发语言·c#
William_cl1 天前
C# MVC 修复DataTable时间排序以及中英文系统的时间筛选问题
开发语言·c#·mvc
c#上位机1 天前
wpf之RelativeSource用法总结
c#·wpf
Dm_dotnet1 天前
WPF应用最小化到系统托盘
c#