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
我来自:
向东博客
查看全文
相关阅读:
深浅复制
iOS 和 H5 页面交互(WKWebview 和 UIWebview cookie 设置)
iPhone 启动页尺寸
AVAssetDownloadURLSession 简述
iOS性能优化
测试用例编写
flutter_boot android和flutter源码阅读记录
com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
android sdk tools里找不到draw9patch.bat 如何制作.9.png 格式图片
排球比赛计分系统
原文地址:https://www.cnblogs.com/meil/p/435660.html
最新文章
【原】iOS开发进阶(唐巧)读书笔记(一)
【原】导入framework报错解决(以ReactiveObjC.framework为例)
【原】UILabel 设置了 attributedText 后省略号不显示
【转】iOS学习之iOS禁止Touch事件
【原】iOS学习之Quartz2D(1)
【原】iOS学习之Xcode8关于控制台不打印错误信息
【转】iOS学习之translucent属性
【原】iOS学习之三种拨打电话方式的比较
【原】iOS学习之图片拉伸处理(类似qq的气泡)
【原】iOS学习之应用之间的操作
热门文章
苹果审核ipv6海外解决思路-About APP Store
使用CocoaPods配置iOS百度地图sdk问题记录20191024
CocoaPods安装和使用201712
关于iPhone设备不同显示尺寸适配的一些方法
iOS字符串处理_替换(去掉空格换行)、截取
关于输入框被键盘覆盖及收回键盘的问题
(deprecated)苹果_公司开发者账号申请_公司账号申请
(deprecated)苹果_公司开发者账号_申请DUNS number
苹果_公司开发者账号_注册Apple ID
学习记忆策略
Copyright © 2011-2022 走看看