标签:
这里介绍一下C#的委托
委托的用处:1、方法参数化2、轮播
1、将方法参数化
public class Test
{
public delegate void TestEventHandler(string name);
public Test()
{
this.Start("run", this.Run);
}
private void Start(string name, TestEventHandler testEventHandler)
{
testEventHandler(name);
}
private void Run(string name)
{
Console.WriteLine(name);
}
}
2.轮播
public class Test
{
public delegate void TestEventHandler(string name);
public TestEventHandler testEventHandler;
public Test()
{
testEventHandler += Run1;
testEventHandler += Run2;
testEventHandler("run");
}
private void Run1(string name)
{
Console.WriteLine(name + "1");
}
private void Run2(string name)
{
Console.WriteLine(name + "2");
}
}
结果:
RUN1
RUN2
这就是轮播
标签:
原文地址:http://www.cnblogs.com/hhxx123/p/4585446.html