文章目录
- 项目地址
- 一、委托
-
- 1.1 委托
-
- 1.2 多播委托
- 1.3 泛型委托
-
- 1. 无返回值Action
- 2. 有返回值Func
- 3. Lambda
-
- 无参无返回值的Lambda
- 有参有返回值的Lambda
- 1.4 应用
-
项目地址
dbt
airflow
一、委托
1.1 委托
1. 无参委托
- Define a parameterless
- Create a function that matches the parameterless delegate
- Assign the function to the delegate.
- Call the delegate

2. 有参委托
- 有参:提问,既然可以直接调用Add(1,2)的方法,为什么要多此一举,使用委托去调用
- Since we can directly call the method Add(1,2), why bother using a delegate to call it?
- If we can directly invoke the method Add(1,2), why go through the extra step of calling it via a delegate?”
- 解答:使用了委托,我们可以在不更换调用的方法的名称(始终调用的是_mathdelegate),只需要切换delegate赋值为符合的格式,就可以实现切换函数。

3. 使用
不好的方法
- 假设我们有3个技能,分别是伤害技能,加血技能,传送技能,三个技能的前2个执行的方法都一样,只是第三个执行的方法不一样,一个是伤害,一个是加血,一个是传送,不好的方法。<