event
时间:2011-12-15
来源:互联网
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
public delegate int Func(int a ,int b);
public class Test
{
public Func <int> Add;
//定义事件
public event Func funcevent;
public int a;
public int b;
public Test(int a, int b)
{
this.a = a;
this.b = b;
}
public int TestAdd(int i, int b)
{
return i + b;
}
public int TestMinus(int a, int b)
{
return a - b;
}
#region 事件
//引发事件的方法
public void multipli()
{
if (funcevent != null)
{
this.funcevent(this.a, this.b);
}
}
#endregion
}
class Program
{
static void Main(string[] args)
{
Test t = new Test(2, 3);
Func fun = t.TestAdd;
fun += t.TestMinus;
Delegate [] DelegateList;
#region 事件
Program program = new Program();
//订阅事件
t.funcevent += program.t_funcevent;
//引发事件
t.multipli();
#endregion
DelegateList = fun.GetInvocationList();
Console.WriteLine( "{0} {1} ", DelegateList[0].DynamicInvoke(1, 2), DelegateList[1].DynamicInvoke(3, 5));
Console.ReadKey();
}
#region 事件
//引发事件的方法
public int t_funcevent(int a, int b)
{
Console.WriteLine( "a*b={0} ", a * b);
return a * b;
}
#endregion
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
public delegate int Func(int a ,int b);
public class Test
{
public Func <int> Add;
//定义事件
public event Func funcevent;
public int a;
public int b;
public Test(int a, int b)
{
this.a = a;
this.b = b;
}
public int TestAdd(int i, int b)
{
return i + b;
}
public int TestMinus(int a, int b)
{
return a - b;
}
#region 事件
//引发事件的方法
public void multipli()
{
if (funcevent != null)
{
this.funcevent(this.a, this.b);
}
}
#endregion
}
class Program
{
static void Main(string[] args)
{
Test t = new Test(2, 3);
Func fun = t.TestAdd;
fun += t.TestMinus;
Delegate [] DelegateList;
#region 事件
Program program = new Program();
//订阅事件
t.funcevent += program.t_funcevent;
//引发事件
t.multipli();
#endregion
DelegateList = fun.GetInvocationList();
Console.WriteLine( "{0} {1} ", DelegateList[0].DynamicInvoke(1, 2), DelegateList[1].DynamicInvoke(3, 5));
Console.ReadKey();
}
#region 事件
//引发事件的方法
public int t_funcevent(int a, int b)
{
Console.WriteLine( "a*b={0} ", a * b);
return a * b;
}
#endregion
}
}
作者: Software_SCF123 发布时间: 2011-12-15
你想干嘛
作者: hyttplay 发布时间: 2011-12-15
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28