class Program
{
static void Main(string[] args)
{
Example example = new Example();
example.Go();
Console.ReadKey();
}
}
public class Example
{
public delegate void DoSth(string str);
internal void Go()
{
//声明一个委托变量,并把已知方法作为其构造函数的参数
DoSth d = new DoSth(Print);
string str = "Hello,World";
//通过委托的静态方法Invoke触发委托
d.Invoke(str);
}
void Print(string str)
{
Console.WriteLine(str);
}
}
public class Example
{
public delegate void DoSth(object sender, EventArgs e);
internal void Go()
{
//声明一个委托变量,并把已知方法作为其构造函数的参数
DoSth d = new DoSth(Print);
object sender = 10;
EventArgs e = new EventArgs();
d(sender, e);
}
void Print(object sender, EventArgs e)
{
Console.WriteLine(sender);
}
}
public class Example
{
public delegate void DoSth(object sender, EventArgs e);
public event DoSth myDoSth;
internal void Go()
{
//声明一个委托变量,并把已知方法作为其构造函数的参数
DoSth d = new DoSth(Print);
object sender = 10;
EventArgs e = new EventArgs();
myDoSth += new DoSth(d);
myDoSth(sender, e);
}
void Print(object sender, EventArgs e)
{
Console.WriteLine(sender);
}
}
public class Example
{
public delegate void DoSth(object sender, EventArgs e);
public event DoSth myDoSth;
internal void Go()
{
//声明一个委托变量,并把已知方法作为其构造函数的参数
DoSth d = new DoSth(Print);
DoSth d1 = new DoSth(Say);
object sender = 10;
EventArgs e = new EventArgs();
//为事件注册多个委托
myDoSth += new DoSth(d);
myDoSth += new DoSth(d1);
myDoSth(sender, e);
}
void Print(object sender, EventArgs e)
{
Console.WriteLine(sender);
}
void Say(object sender, EventArgs e)
{
Console.WriteLine(sender);
}
}
public class Example
{
public delegate void DoSth(object sender, EventArgs e);
public event DoSth myDoSth;
internal void Go()
{
object sender = 10;
EventArgs e = new EventArgs();
//为事件注册多个委托
myDoSth += Print;
myDoSth += Say;
myDoSth(sender, e);
}
void Print(object sender, EventArgs e)
{
Console.WriteLine(sender);
}
void Say(object sender, EventArgs e)
{
Console.WriteLine(sender);
}
}
public delegate void EventHandler(object sender, System.EventArgs e);
public class Example
{
public event EventHandler myEvent;
internal void Go()
{
object sender = 10;
EventArgs e = new EventArgs();
//为事件注册多个委托
myEvent += Print;
myEvent += Say;
myEvent(sender, e);
}
void Print(object sender, EventArgs e)
{
Console.WriteLine(sender);
}
void Say(object sender, EventArgs e)
{
Console.WriteLine(sender);
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有