zoukankan
html css js c++ java
简单的委托事件
class
1
using
System;
2
using
System.Collections.Generic;
3
4
namespace
ConsoleApplication3
5
{
6
/**/
///
<summary>
7
///
事件接受类
8
///
</summary>
9
class
Program
10
{
11
static
void
Main(
string
[] args)
12
{
13
EventSend es
=
new
EventSend();
14
es.myEvent
+=
new
EventSend.myDelegate(es_myEvent);
15
es.Run();
16
}
17
18
private
static
void
es_myEvent(
object
sender,MyEventArgs e)
19
{
20
//
事件处理方法
21
Console.WriteLine(
"
\n你触发了一次事件!\n你输入的是:
"
+
e.InputText);
22
}
23
}
24
/**/
///
<summary>
25
///
事件发送类
26
///
</summary>
27
class
EventSend
28
{
29
public
delegate
void
myDelegate(
object
sender, MyEventArgs e);
//
定义委托
30
public
event
myDelegate myEvent;
//
定义委托类型的事件
31
public
void
Run()
32
{
33
while
(
true
)
34
{
35
Console.BackgroundColor
=
ConsoleColor.Red;
36
Console.ForegroundColor
=
ConsoleColor.Yellow;
37
Console.WriteLine(
"
=== 退出请选择 n 或 N ===
"
);
38
MyEventArgs e1
=
new
MyEventArgs();
39
e1.InputText
=
Console.ReadLine();
40
string
str
=
e1.InputText;
41
if
(str
==
"
n
"
||
str
==
"
N
"
)
42
{
43
break
;
44
}
45
myEvent(
this
, e1);
46
}
47
}
48
}
49
50
/**/
///
<summary>
51
///
事件的内容
52
///
</summary>
53
class
MyEventArgs:EventArgs
54
{
55
private
string
inputText;
56
public
string
InputText
57
{
58
get
59
{
60
return
this
.inputText;
61
}
62
set
63
{
64
this
.inputText
=
value;
65
}
66
}
67
}
68
}
69
每天进步一点点...
查看全文
相关阅读:
权限和分组
验证与授权
CSRF、XSS、clickjacking、SQL 的攻击与防御
上下文处理器及中间件
类和实例
偏函数
生成器
迭代 复习
函数调用 复习
复习 条件判断,循环
原文地址:https://www.cnblogs.com/cyan/p/1287381.html
最新文章
问卷调查
周记第1次
《世界是数字的》读后感
第三周作业1(1)嘎嘎嘎
《我是一只IT小小鸟》读后感
JavaScript 词法、静态、动态作用域初级理解
ubuntu16.04主题美化和软件推荐(转载)
Ubuntu 16.04 LTS sublime text 3 解决不能输入中文
Ubuntu 16.04 LTS U盘安装要点
线程
热门文章
c#面试题
Orcal中的SQL语句
orcal常用函数
sql语句大全
项目部署(ubuntu+uwsgi+nginx+supervisor+django)
视频的上传及购买播放
文件上传
图形 / 短信 :验证码
node.js
Redis
Copyright © 2011-2022 走看看