列举常用的委托

 

1、Action

定义:public delegate void Action();

赋值:

Action action1 = () => { };
Action action2 = delegate() { };

调用:

action1 ();

action2 ();

 

2、Func

定义:public delegate TResult Func<in T, out TResult>(T arg);

赋值:

Func<string, string> func1 = delegate(string str) { return str;};
Func<string, string> func2 = (str) => str;

调用:

func1 ("str");

func2 ("str");

 

其他委托也是类似的写法。

 

相关文章:

  • 2022-01-09
  • 2022-12-23
  • 2022-12-23
  • 2021-11-19
猜你喜欢
  • 2021-09-03
  • 2021-09-18
  • 2021-10-13
  • 2021-12-06
  • 2021-09-27
  • 2021-09-30
相关资源
相似解决方案