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();
相关推荐
Monkey_Xuan17 分钟前
C#中的引用传递和值传递
unity·c#
CreasyChan41 分钟前
C# LINQ 深度解析:优缺点与性能陷阱
unity·c#·游戏开发
精神小伙就是猛1 小时前
C# sealed密封 追本溯源
开发语言·c#
雨季6663 小时前
C 语言学习指南:从入门到实战的系统路径
c#
缺点内向6 小时前
如何在 C# 中创建、读取和更新 Excel 文档
c#·.net·excel
c#上位机6 小时前
halcon创建对象数组——concat_obj
图像处理·计算机视觉·c#·halcon
周杰伦fans7 小时前
Solidworks 二次开发模板SwCSharpAddin
c#
czhc11400756637 小时前
c# winform1212
java·javascript·c#
花北城7 小时前
【C#】DbToLinq多表连接
开发语言·c#
曹牧7 小时前
C#:string.IndexOf
服务器·开发语言·c#