9-2.txt
来自「C#实验报告 C#实验报告 C#实验报告 C#实验报告 C#实验报告 C#实验报」· 文本 代码 · 共 41 行
TXT
41 行
//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 + =
减小字号Ctrl + -
显示快捷键?