Last active
August 29, 2015 14:02
-
-
Save the-takeo/5d8b306939b314fc9db2 to your computer and use it in GitHub Desktop.
Event自前実装の練習
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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