当前位置:网站首页>Unity C # basic review 26 - first acquaintance Commission (p447)
Unity C # basic review 26 - first acquaintance Commission (p447)
2022-06-29 15:12:00 【_ A little QQ】
entrust Delegate
C# Medium Delegate Corresponding to C The pointer in , But it's different C A pointer in can point to a method , It can also point to variables , And you can do type conversion ,
C The pointer in is actually a memory address variable , It can operate memory directly , Through memory
Address direct access to variables , Direct call method .
and C# Medium Delegate It's a strong type of , That is, when the delegate is declared, it has been specified
This variable can only point to a specific parameter , And the method of returning the value .
Use delegate You can directly create a delegation type with any name , When the system is compiled
when , The system will automatically generate this type . You can use delegate void MyDelegate()
Method to create a delegation class , And use ILDASM.exe Observe its members . from ILDASM.exe
Can be seen in , It inherited System.MulticastDelegate class , And automatically generate BeginInvoke、EndInvoke、Invoke Three common methods .
Invoke Method is the corresponding method used to synchronously call the delegate object , and BeginInvoke、EndInvoke Is used to call the corresponding method asynchronously .
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1
{
class Skill
{
public void Skill1()
{
Console.WriteLine("Skill: Skill 1 Animation ");
}
public void Skill2()
{
Console.WriteLine("Skill: Skill 2 Animation ");
}
public void Skill3()
{
Console.WriteLine("Skill: Skill 3 Animation ");
}
public void Skill4()
{
Console.WriteLine("Skill: Skill 4 Animation ");
}
public void Skill5()
{
Console.WriteLine("Skill: Skill 5 Animation ");
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1
{
delegate void AutoSkillPlayer();
class Program
{
static void Main(string[] args)
{
AutoSkillPlayer akp = new AutoSkillPlayer(Skill1);
akp += Skill3;
akp += Skill4;
Skill sk = new Skill();
akp += sk.Skill4;
akp -= Skill1;
akp.Invoke();
}
public static void Skill1()
{
Console.WriteLine(" Skill 1 Animation ");
}
public static void Skill2()
{
Console.WriteLine(" Skill 2 Animation ");
}
public static void Skill3()
{
Console.WriteLine(" Skill 3 Animation ");
}
public static void Skill4()
{
Console.WriteLine(" Skill 4 Animation ");
}
public static void Skill5()
{
Console.WriteLine(" Skill 5 Animation ");
}
}
}

边栏推荐
- 广州期货正规吗?如果有人喊你用自己的手机登,帮忙开户,安全吗?
- Real software testers = "half product + Half development"?
- MCS:离散随机变量——Binomial分布
- Material dynamic self illumination
- Informatics Olympiad all in one 2062: movie tickets
- Unity C# 基础复习26——初识委托(P447)
- MySQL的json 数组操作 json_array_append、json_array_insert
- Chapter IX app project test (4) test tools
- What is the relationship between synchronized and multithreading
- 中国三氧化二砷行业研究与未来预测报告(2022版)
猜你喜欢
随机推荐
卫星运动的微分方程
Ink drop typesetting
Abnormal logic reasoning problem of Huawei software test written test [2] Huawei hot interview problem
Basic use of text preprocessing library Spacy (quick start)
How word automatically generates directories
Lumiprobe reactive dye - amino dye: cyanine 5 amine
Get the width of text component content
MCS:离散随机变量——几何分布
Hi, you have a code review strategy to check
BioVendor遊離輕鏈(κ和λ)Elisa 試劑盒的化學性質
二级指针
synchronized 与多线程的哪些关系
Informatics Olympiad 1001:hello, world!
Lumiprobe deoxyribonucleic acid phosphate CpG 1000 solid carrier
I want to search the hundreds of nodes in the data warehouse. Can I check a table used in the SQL
nfs配置两台主机之间的文件映射
What is the relationship between synchronized and multithreading
Uniapp problem list and experience
Konva series Tutorial 4: drawing attributes
Unity C# 基础复习26——初识委托(P447)









