Skip to content

Instantly share code, notes, and snippets.

@acple
Created March 20, 2015 13:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save acple/f16b086c837deae523c3 to your computer and use it in GitHub Desktop.
Save acple/f16b086c837deae523c3 to your computer and use it in GitHub Desktop.
using System;
namespace ReactiveExtensionsTest
{
class Program
{
public static void Main()
{
var test = new イベント受け取るテスト();
test.Start();
Console.ReadKey(true);
}
}
public class イベント受け取るテスト
{
public void Start()
{
var i = 1; // ichi
var eventTest = new 発行する側クラス<int>();
eventTest.イベント本体 += this.イベント受け取るやつ;
eventTest.イベント発火するやつ(i);
}
public void イベント受け取るやつ(int value)
{
Console.WriteLine($"Eventきたぞ!値は{ value }だぞ!");
}
}
public class 発行する側クラス<T>
{
public event Action<T> イベント本体;
public void イベント発火するやつ(T value)
{
if (this.イベント本体 != null)
{
Console.WriteLine($"今から{ value }を送出するぞ!");
イベント本体(value);
Console.WriteLine($"{ value }を送出したぞ!");
}
}
}
/*/ 実行結果
今から1を送出するぞ!
Eventきたぞ!値は1だぞ!
1を送出したぞ!
/*/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment