首页  韩国资源  酷站加油  我的展厅  设计名站  古典元素  推荐下载  设计欣赏  每周专访  招募精英  人才专区  网页教程  平面设计  编程开发  设计竞赛
当前位置:首页 > 编程开发 > ASP.net教程 > Asp.Net实例教程 > 正文
Google
C#高级编程中的事件DEMO实例
来源:68design.net 2007年10月16日 09:26 网友评论:0条 点击:

 一个C#高级编程中的事件 DEMO 实例,C#高级编程中的例子,讲的是事件DEMO,一起来看看吧。

using System;
  using System.Collections.Generic;
  using System.Text;
  namespace ConsoleApplication1
  {
  class Program
  {
  /// 
  /// 发生一个事件:用户选择了一个选项
  /// 响应是1:用户得到想要的结果
  /// 2:老板得到是否有用户在看他的信息
  ///
  /// 即:多点委托[显示结果,提示老板]
  ///
  /// 
  static void Main(string[] args)
  {
  //UserInputMonitor 的成员userInputRequest 事件
  UserInputMonitor uim = new UserInputMonitor();
  //为userInputRequest绑定2个方法
  UserView uv = new UserView(uim);
  person p = new person(uim);
  //run方法里面会提示用户来促发userInputRequest 事件
  uim.Run();
  }
  }
  }
  using System;
  using System.Collections.Generic;
  using System.Text;
  namespace ConsoleApplication1
  {
  class UserInputMonitor
  {
  public delegate void userInputRequest(object send,UserEventArgs e);
  public event userInputRequest onUserInputRequest;
  public void Run()
  {
  //不同的促发情况
  //UserEventArgs 带上了用户选择的信息
  while (true)
  {
  System.Console.WriteLine("input p:[look personal ]");
  System.Console.WriteLine("input c:[look company]");
  System.Console.WriteLine("input e:[exit ]");
  string input = System.Console.ReadLine();
  if (input.ToLower() == "p")
  onUserInputRequest(this, new UserEventArgs(RequestType.Personal));
  else if (input.ToLower() == "c")
  onUserInputRequest(this, new UserEventArgs(RequestType.Company));
  else if (input.ToLower() == "e")
  return;
  else
  continue;
  }
  }
  }
  }
  using System;
  using System.Collections.Generic;
  using System.Text;
  namespace ConsoleApplication1
  {
  enum RequestType{
  Personal,
  Company
  }
  /// 
  /// 携带了用户选择信息的EventArgs
  /// 
  class UserEventArgs : EventArgs
  {
  private RequestType reqType;
  public RequestType GetRequestType
  {
  get
  {
  return this.reqType;
  }
  }
  public UserEventArgs(RequestType t)
  {
  this.reqType = t;
  }
  }
  }
  using System;
  using System.Collections.Generic;
  using System.Text;
  namespace ConsoleApplication1
  {
  /// 
  /// 绑定一个事件
  /// 
  class UserView
  {
  public UserView(UserInputMonitor uim)
  {
  uim.onUserInputRequest += new UserInputMonitor.userInputRequest(uim_onUserInputRequest);
  }
  protected void uim_onUserInputRequest(object send, UserEventArgs e)
  {
  if (e.GetRequestType == RequestType.Company)
  System.Console.WriteLine("company is best!!");
  if(e.GetRequestType == RequestType.Personal)
  System.Console.WriteLine("he is chinese!!");
  }
  }
  }
  using System;
  using System.Collections.Generic;
  using System.Text;
  namespace ConsoleApplication1
  {
  /// 
  /// 绑定一个事件
  /// 
  class person
  {
  public person(UserInputMonitor uim)
  {
  uim.onUserInputRequest += new UserInputMonitor.userInputRequest(uim_onUserInputRequest);
  }
  protected void uim_onUserInputRequest(object send, UserEventArgs e)
  {
  if (e.GetRequestType == RequestType.Personal)
  System.Console.WriteLine("somebody miss u!!");
  }
  }
  }

上一篇:ASP.NET 2.0 页面状态持续程序   下一篇:解决ASP.NET中GridView控件的隐藏列问题
收藏此页】【打印】【关闭
 相关文章  我要点评
·在Web开发领域编程语言PHP优势在哪
·Java编程思想面向对象逻辑思维方法
·C#与Java相似之处的对比
·JAVA编程中异常问题处理方式的区别
·Java编程语言中的内部类说明
·Java编程语言中的return
·什么是面向接口编程
·对一些编程初学者的良言警句

免责声明:本站刊载此文不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。对本文有任何异议,请联络:68design#163.com
转载要求:作者及来源信息必需保留。转载之图片、文件,链接请不要盗链到本站,且不准打上各自站点的水印。



关于我们 | 在线反馈 | 广告报价 | 友情链接 | 联系我们 | 免责声明 | 在线投稿 | 网站地图
Copyright © 2003-2007 68design.net, All Rights Reserve 【找网页设计师,当然上网页设计师联盟】