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. NOIP2010 提高组合集

    NOIP 2010 提高组合集 T1 机器翻译 模拟题,用一个栈模拟,桶记录即可. #include <iostream> #include <cstdio> #include ...

  2. zoj——3557 How Many Sets II

    How Many Sets II Time Limit: 2 Seconds      Memory Limit: 65536 KB Given a set S = {1, 2, ..., n}, n ...

  3. [bzoj 1025][SCOI2009]游戏(DP)

    题目:http://www.lydsy.com/JudgeOnline/problem.php?id=1025 分析:首先这个问题等价于A1+A2+……Ak=n,求lcm(A1,A2,……,Ak)的种 ...

  4. oracle 12c 初步操作

    查看是否为cdb SQL> select name,cdb,open_mode,con_id from v$database; NAME CDB OPEN_MODE CON_ID ------- ...

  5. 终于理解java的classpath!

    JAVA 的CLASSPATH 上面这样是可以的!!!!哇, 再也不会出现编译或是运行的时候,class 找不到的问题了.终于明白为什么了. java -cp  /ysr/my-app  P  这条命 ...

  6. C++对象内存分布(3) - 菱形继承(virtual)

    1.前言 本篇文章的全部代码样例.假设是windows上编译执行.则使用的是visual studio 2013.假设是RHEL6.5平台(linux kernal: 2.6.32-431.el6.i ...

  7. 小胖说事22-----iOS开发技巧之取消键盘响应和截屏功能

    1.UILable内容模糊 在非Retina的iPad mini 的屏幕上,一个UILable的frame的origin值假设是有小数位(如0.5),就会造成显示模糊,所以不妨用整数值的origin. ...

  8. LeetCode 125. Valid Palindorme (验证回文字符串)

    Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...

  9. go语言笔记——go环境变量goroot是安装了路径和gopath是三方包路径

    Go 环境变量 Go 开发环境依赖于一些操作系统环境变量,你最好在安装 Go 之间就已经设置好他们.如果你使用的是 Windows 的话,你完全不用进行手动设置,Go 将被默认安装在目录 c:/go  ...

  10. ubuntu查看'任务管理器'

    ubuntu下的任务管理器打开方式:命令行输入'gnome-system-monitor'即可,展示如下: