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
我来自:
向东博客
查看全文
相关阅读:
关于李约瑟难题的思考
《MDX解决方案(第2版)》实例数据部署过程
在SQL SERVER 2008种使用表值参数
解决了一个想了很久的问题
发现可以在两个数据库中共享只读文件组
java 包位置
单元测试java
Cannot determine build data storage root for project
Vue——绑定值
浪潮之巅第八章 — 没落的贵族(摩托罗拉)
原文地址:https://www.cnblogs.com/meil/p/435660.html
最新文章
最简单的COM实现例子
VC 6.0动态生成Word表格实例
使VC6编译的程序也使用当前系统风格
使用模板类示例
WinInet类使用方法
VC单文档中加入屏闪信息
深入理解C#的装箱和拆箱
IC design books
RTL风格建议规范
VIM 快速注释
热门文章
AHB_MONITOR
vcs仿真的一个脚本
文件列表拷贝
SVN 的local 方式
IC design flow
专业历程
Setup concepts Verdi ! Verdi
列表页面head升降序排列
MDX中容易搞混的几个概念
关于Descendants()的理解
Copyright © 2011-2022 走看看