Zip

合并兩個序列,產生一個新的對象序列,但連接方式是一对一的(即序列1和第一项连接序列2的第一项),所以最终结果会在较短的序列处终止。

Zip在這裏不是壓縮的意思,而是拉鏈,意爲連接兩個序列

            Person magnus = new Person { Name = "Hedlund, Magnus" };
Person terry = new Person { Name = "Adams, Terry" };
Person charlotte = new Person { Name = "Weiss, Charlotte" }; Pet barley = new Pet { Name = "Barley", Owner = terry };
Pet boots = new Pet { Name = "Boots", Owner = terry };
Pet whiskers = new Pet { Name = "Whiskers", Owner = charlotte };
Pet daisy = new Pet { Name = "Daisy", Owner = magnus }; List<Person> people = new List<Person> { magnus, terry, charlotte };
List<Pet> pets = new List<Pet> { barley, boots, whiskers, daisy }; var query = people.Zip(pets, (person, pet) => new { OwnerName = person.Name, Pet = pet.Name });

结果如下:

Hedlund, Magnus - Barley

Adams, Terry - Boots

Weiss, Charlotte - Whiskers

Join

合并兩個序列,產生一個新的對象序列,相當於内連接

            var query = people.Join(pets,
person => person,
pet => pet.Owner,
(person, pet) => new { OwnerName = person.Name, Pet = pet.Name }); query = from person in people
join pet in pets on person equals pet.Owner
select new { OwnerName = person.Name, Pet = pet.Name };

結果如下:

Hedlund, Magnus - Daisy

Adams, Terry - Barley

Adams, Terry - Boots

Weiss, Charlotte - Whiskers

GroupJoin

合并兩個序列,產生一個分層的對象序列,序列中的每個元素都對應一個列表,這個方法在传统的关系数据库术语中没有直接的等效方法

            var query = people.GroupJoin(pets,
person => person,
pet => pet.Owner,
(person, petCollection) =>
new
{
OwnerName = person.Name,
Pets = petCollection.Select(pet => pet.Name)
}); query = from person in people
join pet in pets on person equals pet.Owner into petCollection //其中petCollection是一個IEnumerable<Pet>
select new
{
OwnerName = person.Name,
Pets = petCollection.Select(pet => pet.Name)
};

結果如下:

> Hedlund, Magnus:

Daisy

> Adams, Terry:

Barley

Boots

> Weiss, Charlotte:

Whiskers

Zip, Join, GroupJoin的更多相关文章

  1. EntityFramework查询--联合查询(Join,GroupJoin)

    首先我们先看一下Join public static IEnumerable<TResult> Join<TOuter, TInner, TKey, TResult>(this ...

  2. 转:EntityFramework查询--联合查询(Join,GroupJoin)

    首先我们先看一下Join public static IEnumerable<TResult> Join<TOuter, TInner, TKey, TResult>(this ...

  3. 《C#高级编程》学习总结之LINQ

    一.标准的查询操作符 标准查询操作符 说明 Where OfType<TResult> 筛选操作符定义了返回元素的条件. Select SelectMany 投射操作符用于把对象转换为另一 ...

  4. Linq to Objects for Java 发布 1.0.1 版本

    现在 java 支持 linq 啦.比原生 stream api 更好用,功能更强大.现已发布 version 1.0.1 地址: https://github.com/timandy/linq. A ...

  5. Rx = Observables(响应) + LINQ(声明式语言) + Schedulers(异步)

    Reactive = Observables(响应)+ Schedulers(异步). Extensions = LINQ(语言集成查询) LINQ: The Operators of Reactiv ...

  6. RxJava 1.x 笔记:组合型操作符

    最近去检查眼睛,发现度数又涨了,唉,各位猿多注意保护自己的眼睛吧! 前面学了 RxJava 的三种关键操作符: 创建型操作符 过滤型操作符 变换型操作符 读完本文你将了解第四种(组合型操作符): 组合 ...

  7. Threading in C# 5

    Part 5: Parallel Programming In this section, we cover the multithreading APIs new to Framework 4.0 ...

  8. C# LINQ(10)

    LINQ 查询 var query = from r in Formula1.GetChampions() where r.Country == "Brazil" orderby ...

  9. C#基础提升系列——C# LINQ

    C# LINQ LINQ(Language Integrated Query,语言集成查询).在C# 语言中集成了查询语法,可以用相同的语法访问不同的数据源. 命名空间System.Linq下的类En ...

随机推荐

  1. 20180710使用gh

    转自:http://www.ywnds.com/?p=14265 一.背景 GitHub正式宣布以开源的方式发布gh-ost:GitHub的MySQL无触发器在线更改表定义工具!下面是官方给出gh-o ...

  2. Ubuntu查看系统版本的方法

    1. less /etc/issue 2. less /proc/version 3. uname -a 4. lsb_release -a

  3. bbed改动undo段状态(ORA-01578)

    ZBDBA@orcl11g>select * from zbdba; select * from zbdba * ERROR at line 1: ORA-01578: ORACLE data ...

  4. Office 如何打印A4不干胶标签纸

    1 下载Label Expert这个软件,注意不是第一个Avery Wizard(卖家可能会送你这个软件,但是送的这款软件是简体中文版的,似乎模板不全,所以最好还是自己下,反正我最后是由于找不到对应的 ...

  5. 解析cocos2d-lua项目中的Hello World

    创建完cocos2d-x的lua项目后.打开项目的Resources目录,找到hello.lua.cocos2d-x的lua项目的測试样例主要就是由这个脚本文件运行的. require "A ...

  6. C#邮件发送(含附件)

    class SendEmail { static void Main(string[] args) { string from = "发件人@yingu.com"; string ...

  7. 百度开放云java+tomcat部署web项目-小皇帝詹姆斯

    加入部署 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/diss ...

  8. R环境中的工作空间(workspace)

    工作空间(workspace)就是当前R的工作环境,它储存着全部用户定义的对象(向量.矩阵.函数.数据框.列表) . 在一个R会话结束时,你能够将当前工作空间保存到一个镜像中.并在下次启动R时自己主动 ...

  9. debian使用过程中常见的问题

    1 wget https://www.dropbox.com ERROR: The certificate of `www.dropbox.com' is not trusted. ERROR: Th ...

  10. 构建一个简单的基于MVC模式的JavaWeb

    零晨三点半了,刚刚几个兄弟一起出去吼歌,才回来,这应该是我大学第二次去K歌,第一次是大一吧,之后每次兄弟喊我,我都不想去,因为我还是很害怕去KTV,或许是因为那里是我伤心的地方,也或许是因为我在那里失 ...