c# Delegate 例子
来源:互联网 发布:排序算法应用 编辑:程序博客网 时间:2024/05/21 19:37
using System;
using System.IO;
using System.Text;
using System.Collections.Generic;
using System.Text.RegularExpressions;
namespace ConsoleApplication2
{
class MyDelegateTest
{
public class KeyInputClass
{
public delegate void KeyInEventHander(string str);
public event KeyInEventHander KeyinEvent;
public void KeyInput()
{
Console.WriteLine("please keyin:");
string str = Console.ReadLine();
str = Regex.Replace(str, "[^a-z]", "");
KeyinEvent(str);
//string str = Console.ReadKey().ToString();
//Match s = Regex.Match(str,"[a-z]");
//if(s.Success)
//{
//KeyinEvent(str);
//}
}
}
public class KeyOutputClass
{
public void KeyOutput(string str)
{
Console.WriteLine("Output {0} if key is lower-case",str);
}
}
public class KeylogClass
{
public void Keylog(string str)
{
if (!File.Exists("c:\\logtest.txt"))
{
Console.WriteLine("create File file:c:\\logtest.txt ,please retry");
File.CreateText("c:\\logtest.txt");
return;
}
Console.WriteLine("Add log string({0}) to file:c:\\logtest.txt,if no exist file,will create it",str);
Console.WriteLine("Input Enter-key quit");
StreamWriter sw = new StreamWriter(@"C:\\logtest.txt", true);
sw.WriteLine(str);
sw.Close();
}
}
static void Main()
{
KeyInputClass ki = new KeyInputClass();
KeyOutputClass ko = new KeyOutputClass();
KeylogClass kl = new KeylogClass();
ki.KeyinEvent+=new KeyInputClass.KeyInEventHander(ko.KeyOutput);
ki.KeyinEvent+=new KeyInputClass.KeyInEventHander(kl.Keylog);
ki.KeyInput();
Console.Read();
}
}
}
- c# Delegate 例子
- C# delegate event 例子
- c#委托delegate简单例子
- C#中多重委托(Multicast Delegate)的例子
- C# Delegate
- C# delegate
- C# Delegate
- C# - Delegate
- C# delegate
- C# delegate
- C# delegate
- C# delegate
- c# delegate
- C# Delegate
- c# delegate
- Delegate.BeginInvoke例子
- dojo 委托 delegate 例子
- Delegate.BeginInvoke例子
- 多线程 改变目录问题
- Emacs下工程的编译:makefile
- 监听edittext中文字个数变化··
- 关于使用ssh框架时,pojo、dao、service三层的关系 .
- 给定一个十进制数,转换为对应的二进制数
- c# Delegate 例子
- HibernateDaoSupport详解
- try-catch-finally(C# 参考)
- JAVA关键字transient
- 自动ssh登录的几种方法
- [PHP]如果客户端禁用cookie,session还能用吗?(终于找到了答案)
- 生成随即验证码图片
- 哥终于知道了苹果为什么发布的是iPhone 4S而非iPhone 5
- PHP5.3.x安装Zend Optimizer(Zend Guard Loader)[Linux][Windows]