Skip to content

Instantly share code, notes, and snippets.

@the-takeo
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save the-takeo/5d8b306939b314fc9db2 to your computer and use it in GitHub Desktop.
Save the-takeo/5d8b306939b314fc9db2 to your computer and use it in GitHub Desktop.
Event自前実装の練習
using System;
namespace EventPractice
{
class TestEventArgs : System.EventArgs
{
public int Num;
public TestEventArgs(int num)
{
this.Num = num;
}
}
delegate void TestEventHandler(object source, TestEventArgs e);
class TestEventClass
{
public event TestEventHandler Test;
public void DoEvent(int num)
{
TestEventArgs args = new TestEventArgs(num);
Test(this, args);
Console.WriteLine("EventWrite");
}
}
class Program
{
static void Main(string[] args)
{
TestEventClass testEventClass = new TestEventClass();
testEventClass.Test += testEventClass_Test;
int test = 12345;
testEventClass.DoEvent(test);
Console.ReadLine();
}
static void testEventClass_Test(object source, TestEventArgs e)
{
Console.WriteLine(e.Num);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment