博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C#入门经典Lambda
阅读量:7077 次
发布时间:2019-06-28

本文共 2076 字,大约阅读时间需要 6 分钟。

1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5  6 namespace LambdaSample 7 { 8     class Program 9     {10         static void Main(string[] args)11         {12             int[] myIntArray = { 1,2, 3, 4, 5 };13             //累加器计算数组总和 14             int result = myIntArray.Aggregate((paramA, paramB) => paramA + paramB);15             int result1 = myIntArray.Aggregate
((paramA, paramB) => paramA + paramB);16 int result2 = myIntArray.Aggregate
(0, (paramA, paramB) => paramA + paramB);17 //递归计算数组总和18 int result3 = count(5);19 Console.WriteLine("The Result is: " + result);20 Console.WriteLine("The Result1 is: " + result1);21 Console.WriteLine("The Result2 is: " + result2);22 Console.WriteLine("The Result3 is: " + result3);23 24 string[] myStrArray = { "Admin", "Change", "ByPage" };25 //字符串数组拼接 何问起26 string strResult = myStrArray.Aggregate((paramA, paramB) => paramA + " " + paramB);27 //字符串数组字符串总长度计算28 int result4 = myStrArray.Aggregate
(0, (a, b) => a + b.Length);29 //字符串数组拼接2,增加字符串"Some curries: "30 string strResult1 = myStrArray.Aggregate
("Some curries: ", (a, b) => a + " " + b);31 //字符串数组字符串总长度计算2 hovertree.com32 int result5 = myStrArray.Aggregate
("Some curries: ", (a, b) => a + " " + b, a => a.Length);33 Console.WriteLine("The StrResult is: " + strResult);34 Console.WriteLine("The Result4 is: " + result4);35 Console.WriteLine(strResult1);36 Console.WriteLine("The Result5 is: " + result5);37 Console.ReadKey();38 }39 40 static int count(int n)41 {42 if (n == 1)43 {44 return 1;45 }46 return n + count(n - 1);47 }48 }49 }

转自:

参考:  

开发技术文章收集: 

转载地址:http://xldml.baihongyu.com/

你可能感兴趣的文章
【BIEE】11_BIEE图形报表在谷歌浏览器64.0.3282.140中访问图例乱码解决
查看>>
【java】java 中 byte[]、File、InputStream 互相转换
查看>>
Beta分布从入门到精通
查看>>
[LeetCode] Redundant Connection II 冗余的连接之二
查看>>
这个博客第二次过年了
查看>>
HDU 2516 取石子游戏(斐波那契博弈)
查看>>
Nginx网站常见的跳转配置实例
查看>>
GitFlow工作流常用操作流程
查看>>
asp.net跳出iframe结构转向登录
查看>>
QTTabBar
查看>>
说出JAVA中一些常用的类,包,接口,请各举5个~~~
查看>>
MODBUS协议整理——功能码简述
查看>>
eclipse里maven项目An error occurred while filtering resources解决办法
查看>>
MySQL导入SQL文件及常用命令
查看>>
java基础-引用数据类型之二维数组(Array)
查看>>
openfalcon的安装和使用
查看>>
Swift编程语言学习1.7——断言
查看>>
Math.round(),Math.ceil(),Math.floor()的区别
查看>>
Spring知识结构
查看>>
16.QT-QMap和QHash解析
查看>>