⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 9-2.txt

📁 C#实验报告 C#实验报告 C#实验报告 C#实验报告 C#实验报告 C#实验报告 C#实验报告
💻 TXT
字号:
//Step 1. Class that defines data for the event
//
public class AlarmEventArgs : EventArgs 
   {   
      private readonly bool snoozePressed = false;
      private readonly int nrings = 0;
      // Constructor.
      public AlarmEventArgs(bool snoozePressed, int nrings) {...}
      // Properties.
      public int NumRings{ get { return nrings;}}
      public bool SnoozePressed { get { return snoozePressed;}}    
      public string AlarmText { get {...}}

   }
   
//Step 2. Delegate declaration.
//
public delegate void AlarmEventHandler(object sender, AlarmEventArgs e);

// Class definition.
//
public class AlarmClock 
{
//Step 3. The Alarm event is defined using the event keyword.
//The type of Alarm is AlarmEventHandler.
  public event AlarmEventHandler Alarm;
//
//Step 4. The protected OnAlarm method raises the event by invoking 
//the delegates. The sender is always this, the current instance of 
//the class.
//   
protected virtual void OnAlarm(AlarmEventArgs e) 
{
    if (Alarm != null) 
     {
       //Invokes the delegates.
       Alarm(this, e); 
      }
   }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -