forked from dotnet/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevent_1.cs
More file actions
21 lines (18 loc) · 716 Bytes
/
Copy pathevent_1.cs
File metadata and controls
21 lines (18 loc) · 716 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
public class SampleEventArgs
{
public SampleEventArgs(string s) { Text = s; }
public String Text {get; private set;} // readonly
}
public class Publisher
{
// Declare the delegate (if using non-generic pattern).
public delegate void SampleEventHandler(object sender, SampleEventArgs e);
// Declare the event.
public event SampleEventHandler SampleEvent;
// Wrap the event in a protected virtual method
// to enable derived classes to raise the event.
protected virtual void OnRaiseSampleEvent()
{
// Raise the event by using the () operator.
SampleEvent?.Invoke(this, new SampleEventArgs("Hello"));
}