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
我来自:
向东博客
查看全文
相关阅读:
概念
Jquery和Aspnet前台控件及后台代码交互
未能找到引用的组件“Microsoft.Office.Core
C#操作Excel,调用ApplicationClass.Quit()关闭Excel时,发生异常:Microsoft Office Word 遇到问题需要关闭
Javasrcipt捕获按键
使用Interop.Excel生成Excel
Javasrcipt时间相关函数
(转)各种纹理贴图技术
(转)立体纹理
(转)地形碰撞高度计算
原文地址:https://www.cnblogs.com/meil/p/435660.html
最新文章
WPF笔记(1.9 样式和控件模板)——Hello,WPF!
WPF笔记(2.9和2.10)——Layout
WPF笔记(2.5 Canvas)——Layout
开始FlexWiki之旅 1
WPF笔记(2.7 文字布局)——Layout
WPF笔记(3.3 内置控件)——Controls
WPF笔记(2.4 Grid)——Layout
malloc realloc calloc
迷宫求解终结版(堆栈的使用)第三季
迷宫求解
热门文章
jsp头文件的内容/response.setHeader
东北话你知道多少?
东北话注解
教务处管理系统(线性链表)
键盘上ctrl各种快捷键大全(备案)
rand()函数的讲解(转载)
jsp的servlet容器跳转是出现乱码(转载) 挺经典的
使用Interop.Excel生成Word表格文档
JQuery 选择和过滤方法总结(转)
AppendFormat System.FormatException: 输入字符串的格式不正确
Copyright © 2011-2022 走看看