Last active
November 27, 2016 13:14
-
-
Save dykarohora/0c353478517b8899907b3cc4aeeb5b96 to your computer and use it in GitHub Desktop.
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; | |
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