设为首页 加入收藏

TOP

C#事件和委托(C#学习笔记03)(二)
2019-10-10 11:17:37 】 浏览:340
Tags:事件 委托 学习 笔记
er(fs); }
public void Logger(string info) //信息写入文档 { sw.WriteLine(info); } public void Close() { sw.Close(); fs.Close(); } } // 事件订阅器 public class RecordBoilerInfo { static void Logger(string info) //控制台输出信息 { Console.WriteLine(info); }//end of Logger static void Main(string[] args) { BoilerInfoLogger filelog = new BoilerInfoLogger("?boiler.txt"); //打开日志文件 DelegateBoilerEvent boilerEvent = new DelegateBoilerEvent(); //实例化DelegateBoilerEvent类,事件发布器 boilerEvent.BoilerEventLog += new DelegateBoilerEvent.BoilerLogHandler(Logger); //boilerEvent.BoilerEventLog为委托的实例,将Logger添加进委托 boilerEvent.BoilerEventLog += new DelegateBoilerEvent.BoilerLogHandler(filelog.Logger); //filelog是BoilerInfoLogger类的实例化,将其中的Logger函数添加进委托 boilerEvent.LogProcess(); //执行LogProccess函数 filelog.Close(); }//end of main }//end of RecordBoilerInfo }

 

 

执行结果:

Logging Info:

Temparature 100
Pressure: 12

Message: O. K

 

首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇WPF自定义控件与样式(3)-TextBox .. 下一篇类型和变量(C#学习笔记02)

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目