首页 技术 正文
技术 2022年11月15日
0 收藏 533 点赞 4,699 浏览 1611 个字

参考页面:

http://www.yuanjiaocheng.net/ASPNET-CORE/asp.net-core-environment.html

http://www.yuanjiaocheng.net/ASPNET-CORE/newproject.html

http://www.yuanjiaocheng.net/webapi/web-api-gaisu.html

http://www.yuanjiaocheng.net/webapi/create-web-api-proj.html

http://www.yuanjiaocheng.net/webapi/test-webapi.html

直接上代码:

IEnumerable<, );int all = list.Aggregate((sum, index) => sum + index);

调试, 第一次调用,发现sum和index分别取列表的第1和第2个值:

F5下一步,发现把index加到sum了 (sum += index), 然后index取下一个值, 并累积到sum,重复此步骤直到取完列表中的值:

最后计算结果是65

另外2个重载函数:

, (sum, index) => sum + index);

第2个参数与上一个例子参数一样,累积列表中值,第1个参数是初始值, 会应用到累积值,在这里相当于用10加65,计算结果75。

, (sum, index) => sum + index, res => res == );

第1第2个参数同上,第3个参数是对累积结果做判断,在这个例子里判断累积结果是否等于75,计算结果是true。

从中可以发现,list.Aggregate((sum, index) => sum + index)其实是list.Aggregate(0, (sum, index) => sum + index)的特例,相当于初始值为0而已。

===================

Join使用,看代码

Persion结构:

public struct Persion        {            public int index;            public string name;            public Persion(int index, string nm)            {                this.index = index;                name = nm;            }        }

Pet结构:

public struct Pet        {            public string name;            public Persion owner;            public Pet(string name, Persion person)            {                this.name = name;                owner = person;            }        }

Persion_Pet结构:

public struct Persion_Pet        {            public string persionName;            public string petName;            public Persion_Pet(string persion, string pet)            {                persionName = persion;                petName = pet;            }        }

Join使用:

Persion p1 = , "张三");            Persion p2 = , "李四");            Persion p3 = , "路人甲");            List<Persion> people = new List<Persion>() { p1, p2, p3 };            Persion p4 = , "路人乙");            Pet dog = new Pet("欢欢", p1);            Pet cat = new Pet("咪咪", p2);            Pet cat2 = new Pet("cat2", p4);            List<Pet> petList = new List<Pet>() { dog, cat, cat2 };            var res = people.Join(petList, persion => persion, pet => pet.owner, (persion, pet) => new Persion_Pet(persion.name, pet.name)).ToList();

结果:

关键在于join会比较第2个参数与第3个参数的返回值,只有相等时才会继续第4个参数。

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,031
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,520
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,368
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,148
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,781
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,862