namespace WindowsFormsApp
{
class MyClass
{
private delegate void MyDelegate(string s);//创建一个实例化委托
static void Maim(string [] args)
{
MyDelegate D1,D2,D3;
D1 = TestMethod1;//绑定委托事件
D2 = TestMethod2;
D3 = TestMethod3;
D1("123");//调用委托事件
D2("456");
D3("789");
}
private void TestMethod1(string str)
{
Console.WriteLine("方法1:{0}", str);
}
private void TestMethod2(string str)
{
Console.WriteLine("方法2:{0}", str);
}
private void TestMethod3(string str)
{
Console.WriteLine("方法3:{0}", str);
}
}
}
C#委托使用
最新推荐文章于 2024-07-10 17:37:23 发布