Lambda表达式 《自学系列》

来源:互联网 发布:聚类算法数据集 编辑:程序博客网 时间:2024/06/06 01:55

 

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace Lambda表达式{    delegate int 两个整型操作委托(int a, int b);    class Program    {        static void 每个委托操作(两个整型操作委托 委托)        {            for (int aa = 1; aa <= 6; aa++)            {                for (int bb = 1; bb <= 6; bb++)                {                    int 委托调用结果 = 委托(aa, bb);                    Console.Write("({0},{1})={2}", aa, bb, 委托调用结果);                    if (bb != 6) Console.Write(",");                }                Console.WriteLine();            }            Console.WriteLine();        }        static void Main(string[] args)        {            每个委托操作((a, b) => a + b);            每个委托操作((a, b) => a * b);            每个委托操作((a, b) => (a - b) % b);            string[] 数据源 = { "每个委托操作", "委托调用结果", "Lambda表达式" };            Console.WriteLine(数据源.Aggregate((c, d) => c + " " + d));            Console.WriteLine(数据源.Aggregate<string, int>(0, (c, d) => c + d.Length));            Console.WriteLine(数据源.Aggregate<string, string, string>("调用结果", (c, d) => c + " " + d, c => c));            Console.WriteLine(数据源.Aggregate<string, string, int>("调用结果", (c, d) => c + " " + d, c => c.Length));            Console.ReadKey();        }    }}


 

0 0
原创粉丝点击