Skip to content

Instantly share code, notes, and snippets.

@dykarohora
Last active November 27, 2016 13:14
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 dykarohora/0c353478517b8899907b3cc4aeeb5b96 to your computer and use it in GitHub Desktop.
Save dykarohora/0c353478517b8899907b3cc4aeeb5b96 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
public class SampleEventArgs : EventArgs
{
public int x { get; private set; }
public int y { get; private set; }
public SampleEventArgs(int x, int y) : base()
{
this.x = x;
this.y = y;
}
}
public delegate void SampleEventHandler(object sender, SampleEventArgs eventArgs);
public class Sender
{
event SampleEventHandler OnCalc;
public void eventStart(int x, int y)
{
OnCalc(this, new SampleEventArgs(x, y));
}
public Sender(List<Receiver> receivers)
{
foreach (var receciver in receivers)
OnCalc += receciver.Add;
}
}
public class Receiver
{
public void Add(object sender, SampleEventArgs eventArgs)
{
if (eventArgs != null)
{
Console.WriteLine(eventArgs.x + eventArgs.y);
Console.Read();
}
}
}
public class Program
{
static void Main(string[] args)
{
List<Receiver> receiverList = new List<Receiver>();
receiverList.Add(new Receiver());
Sender sender = new Sender(receiverList);
sender.eventStart(1, 2);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment