zoukankan
html css js c++ java
一个C#实现的最简单的委托例子
using
System;
namespace
DelegateSample
{
public
delegate
void
PrintCallback(
int
number);
public
class
Printer
{
//
委托定义
private
PrintCallback _print;
//
委托将要依附的属性
public
PrintCallback PrintCallback
{
get
{
return
_print;}
set
{_print
=
value;}
}
}
public
class
Driver
{
//
将要委托的事件
private
void
PrintInteger(
int
number)
{
Console.WriteLine(
"
From PrintInteger:The number is {0}.
"
, number);
}
static
void
Main(
string
[] args)
{
Driver driver
=
new
Driver();
Printer printer
=
new
Printer();
//
将委托绑定到属性
printer.PrintCallback
=
new
PrintCallback(driver.PrintInteger);
//
使用属性触发委托事件
printer.PrintCallback(
10
);
printer.PrintCallback(
100
);
Console.WriteLine(
"
press Enter to exit
"
);
Console.ReadLine();
}
}
}
结果:
From PrintInteger:The number
is
10
.
From PrintInteger:The number
is
100
.
press Enter to exit
我来自:
向东博客
查看全文
相关阅读:
淘宝放大镜
碰撞的小球
模拟微博发布
CSS兼容IE Firefox问题与解决方法
太阳八大行星运行轨迹
Canvas标签基础
offsetTop、clientTop、scrollTop、offsetTop
js绘制圆形时钟
js时钟
js五星好评2
原文地址:https://www.cnblogs.com/meil/p/435660.html
最新文章
skywalking 5.X 分布式链路跟踪 使用笔记
python学习笔记(9)--函数
python学习笔记(8)--random库的使用
python学习笔记(5)-time库的使用
linux上如何让other用户访问没有other权限的目录
linux audit (9)--生成audit报表
linux audit审计(8)--开启audit对系统性能的影响
linux audit审计(8)--ausearch搜索audit日志文件
linux audit审计(7)--读懂audit日志
linux audit审计(7-1)--读懂audit日志
热门文章
自定义equals
RestTemplate 发送Post 多个参数请求
java四舍五入
列表处理
java 文件过滤
粗字体
java JWT应用
springboot-vue-JWT使用
UTC时间转为正常日期
URL特别字符处理
Copyright © 2011-2022 走看看