使用系统自带的委托

来源:互联网 发布:闪讯mac鉴定失败 编辑:程序博客网 时间:2024/06/05 12:49
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace LambdaSpace{    class SystemDelegate    {        public static void Show()        {            //无返回值的系统委托 Action            Action act1 = () => { };            Action<string, int, DateTime> act2 = (x, y, z) => Console.WriteLine("12");//最多接受16个参数,x、y、z省略了类型            //有返回值的系统委托 Func            Func<int> func1 = () => { return 1; };//最后一个模版参数列表的类型是返回值的类型,                                                  //此处只有一个即表示:函数没有参数,且返回值为int            Func<string, int, DateTime, int> func2 = (x, y, z) => { return 1; };//表示带三个参数的,且返回值为int            //因此,自己写代码不需要再自己定义委托,而可以直接使用系统自带的委托        }    }}

0 0
原创粉丝点击