sample code

This commit is contained in:
2023-05-11 11:47:56 +09:00
parent ff8222b942
commit 2a2319833a
9 changed files with 257 additions and 0 deletions

View 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);
}
}
}