All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
SQL循序渐进(19)DISTINCT和排除复制_[SQL,Server教程]
delphi单选框组件(TRadioButton)使用实例
SQLSERVER2005的混和身份验证模式的设置以及SA登陆问题_[SQL Server教程]
SQL Server 错误 ’80040e31’ 超时已过期_[SQL Server教程]
ASP.NET生成静态页面实现方法_[Asp.Net教程]
关于URL传递日文字符乱码问题的解决方案_.net资料_编程技术
混乱的MVC,.NET非要MVC不可么?_.net资料_编程技术
server2008系统安装Microsoft.NET,Framework3.5_.net资料_编程技术
再谈.Net,异步处理_[Asp.Net教程]
使用C#实现阿拉伯数字到大写中文的转换_[Asp.Net教程]
Reading number is top 10 pictures
无题
Look for from human art net, is good--2
Street street fighting
The money of more than 100 countries and regions17
The money of more than 100 countries and regions7
Small QiShu -- ShuangShuangPan2
这才叫绝色美女2
俄罗斯台球天后惊艳魅惑1
王艳写真温柔如水1
世界各国15岁的MM有什么不同
Download software ranking
I for your crazy
变速齿轮3.26
Tram sex maniac 2 (H) rar bag15
Sora aoi - one of more PK
Boxer vs Yellow3
Tram sex maniac 2 (H) rar bag14
C#与.NET技术平台实战演练
电车之狼R
WebService在.NET中的实战应用教学视频 → 第2集
linux初级教程
aaa published in(发表于) 2013/12/18 8:06:16 Edit(编辑)
一个C#高级编程中的事件,DEMO,实例_.net资料_编程技术

一个C#高级编程中的事件,DEMO,实例_.net资料_编程技术

一个C#高级编程中的事件 DEMO 实例_.net资料_编程技术-你的首页-uuhomepage.com

  一个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!!");
  }
  }
  }





添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.