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
我来自:
向东博客
查看全文
相关阅读:
js --- for in 和 for of
vue -- config index.js 配置文件详解
vue -- 脚手架之webpack.dev.conf.js
vue --- 解读vue的中webpack.base.config.js
vue 引入第三方字体包
js call 和 apply
vue2.0中的$router 和 $route的区别
懒加载js实现和优化
vue的指令在webstrom下报错
BFC的布局规则和触发条件
原文地址:https://www.cnblogs.com/meil/p/435660.html
最新文章
使用SourceTree
人的天性法则定律
frame,bounds,center分析
Precompile Prefix file(.pch文件)
Hosts文件是什么?
IOS中通知中心(NSNotificationCenter)的使用总结
网址收藏
右侧固定,左侧自由滚动
点击按钮左右滚动
地区切换
热门文章
点赞+1特效
CSS单行、多行文本溢出显示省略号(……)
CSS强制性换行
关于jQuery的条件判断问题
关于tab选项卡,选项的css问题。
hover带有动画效果的导航
es6 -- Iterator 和 for...of 循环
es6 -- 透彻掌握Promise的使用,读这篇就够了
js -- fileData 实现文件断点续传
使用h5 <a>标签 href='url' download 下载踩过的坑
Copyright © 2011-2022 走看看