C#委托探索之猫和老鼠
作者:网络转载 发布时间:[ 2013/8/21 10:09:19 ] 推荐标签:
鼠类:
public class Mouse
{
public string Name { get; set; }
public Mouse(Cat cat)
{
cat.Scream += new Cat.ScreamEventHandler(cat_Scream);
cat.Scream += this.RunAway;
}
public void RunAway(object sender, ScreamEventArgs e)
{
Cat c = (Cat)sender;
Console.WriteLine("{0} coming,she said:"{1}",{2} running!(Running...)", c.Name, e.Msg, this.Name);
}
void cat_Scream(object sender, ScreamEventArgs e)
{
Cat c = (Cat)sender;
Console.WriteLine("{0} coming,she said:"{1}",{2} running!", c.Name, e.Msg, this.Name);
}
}
这里的委托定义和.net Framework 类库定义方式相同,有助于了解系统提供的委托机制,所以还有一个猫叫事件的参数类:
public class ScreamEventArgs
{
public readonly string Msg;
public ScreamEventArgs(string msg)
{
this.Msg = msg;
}
}
相关推荐
更新发布
功能测试和接口测试的区别
2023/3/23 14:23:39如何写好测试用例文档
2023/3/22 16:17:39常用的选择回归测试的方式有哪些?
2022/6/14 16:14:27测试流程中需要重点把关几个过程?
2021/10/18 15:37:44性能测试的七种方法
2021/9/17 15:19:29全链路压测优化思路
2021/9/14 15:42:25性能测试流程浅谈
2021/5/28 17:25:47常见的APP性能测试指标
2021/5/8 17:01:11