一个简单的Delegate使用例子
来源:互联网 发布:阿里云cdn防盗链 编辑:程序博客网 时间:2024/05/09 02:43
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace delegateDemo
{
class Program
{
static void OtherClassMethod()
{
Console.WriteLine("another class's static method");
}
static void Main(string[] args)
{
var test = new TestDelegate();
test.delegateMethod = new TestDelegate.DelegateMethod(test.NonStaticMethod);
test.delegateMethod += new TestDelegate.DelegateMethod(TestDelegate.StaticMethod);
test.delegateMethod += Program.OtherClassMethod;
test.RunDelegateMethods();
}
}
class TestDelegate
{
public delegate void DelegateMethod(); //声明了一个Delegate Type
public DelegateMethod delegateMethod; //声明了一个Delegate对象
public static void StaticMethod()
{
Console.WriteLine("Delegate a static method");
}
public void NonStaticMethod()
{
Console.WriteLine("Delegate a non-static method");
}
public void RunDelegateMethods()
{
if (delegateMethod != null)
{
Console.WriteLine("---------");
delegateMethod.Invoke();
Console.WriteLine("---------");
}
}
}
}
- 一个简单的Delegate使用例子
- 使用delegate的例子
- 简单的Delegate(委托)例子
- Delegate简单的小例子
- 委托delegate的学习.+一个简单的委托和委托链的例子
- 委托delegate的学习.+一个简单的委托和委托链的例子
- 简单的delegate代理使用
- 使用delegate的一个demo
- Canlendar类使用的一个简单例子
- Canlendar类使用的一个简单例子
- 一个使用多媒体定时器的简单例子
- 使用Google Test的一个简单例子
- 关于ColorBox使用的一个简单例子
- Apache Lucence 使用的一个简单例子
- 使用Google Test的一个简单例子
- 使用OpenMP的一个简单例子
- valgrind使用的一个简单例子
- AN popwindow使用的一个简单例子
- Caliburn.Micro入门
- 面试题(含 runloop)
- OpenGL Super Bible 6th
- 解读加拿大综合类大学排名 提升雅思成绩刻不容缓
- Vim配置#Vim中实现php代码自动完成,提示功能
- 一个简单的Delegate使用例子
- RecyclerView点击事件
- PG数据库事务隔离级别
- 1st round, 285 Inorder Successor in BST
- xml解析(配置文件的pull解析)
- 读《游戏物理引擎开发》
- linux signal, sigaction.sa_mask, sigwait的区别
- elipse启动报错
- Linux如何卸载挂载文件