首页 > Windows开发 > 详细

C#:关于Action和Func以及Eventhandler的区别

时间:2019-11-05 16:04:38      阅读:217      评论:0      收藏:0      [点我收藏+]

三者都是对委托的简写,少了部分委托的声明

Action相当于可以带很多参数的无返回值的委托

public Action<string, int> action;
     public void Action1(string str,int a)
    {
        print(str + a.ToString()); 
    }
        action = Action1;

 

Func可以带很多参数,但是必须带返回值的委托

Func<T1,T2,T3,T4,TResult> func;

    public Func<string , bool> func;
    public bool Func1(string str)
    {
        print(str);

        return true;
    }

EventHandler可以带一整个参数列表,无返回值

    public event EventHandler<StudentClass> showStudentInfo;
    StudentClass student = new StudentClass("12","lp","man");

    private void Test(EventHandler eventHandler)
    {
        eventHandler(this ,student);
    }
//其中 写类对参数列表类进行继承
public class StudentClass : EventArgs
{
    public string age;
    public string name;
    public string sex;

    public StudentClass(string _age,string _name,string _sex)
    {
        age = _age;
        name = _name;
        sex = _sex;
    }

 

 

 

 

 

 

 

C#:关于Action和Func以及Eventhandler的区别

原文:https://www.cnblogs.com/zbyglls/p/11798808.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!