sample code
This commit is contained in:
33
MySolution/ConsoleApp/Samples/EventSample.cs
Normal file
33
MySolution/ConsoleApp/Samples/EventSample.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
|
||||
namespace Samples
|
||||
{
|
||||
public delegate void CustomEventHandler(object sender, EventArgs e);
|
||||
|
||||
class EventSample
|
||||
{
|
||||
public static void Sample()
|
||||
{
|
||||
Button button = new Button();
|
||||
button.Click += new CustomEventHandler(Button_Click);
|
||||
|
||||
button.OnClick();
|
||||
}
|
||||
|
||||
private static void Button_Click(object sender, EventArgs e)
|
||||
{
|
||||
System.Console.WriteLine("Button clicked!");
|
||||
}
|
||||
}
|
||||
|
||||
class Button
|
||||
{
|
||||
public event CustomEventHandler Click;
|
||||
|
||||
public void OnClick()
|
||||
{
|
||||
if (Click != null)
|
||||
Click(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user