Skip to content

Instantly share code, notes, and snippets.

@luisdeol
Created January 7, 2018 23:09
Show Gist options
  • Save luisdeol/244954b71abdcfb3060d0c079b694f92 to your computer and use it in GitHub Desktop.
Save luisdeol/244954b71abdcfb3060d0c079b694f92 to your computer and use it in GitHub Desktop.
Event using event keyword and Event Handler
using System;
namespace create_implement_events_callbacks
{
public class MyArgs : EventArgs
{
public MyArgs(string value)
{
Value = value;
}
public string Value { get; set; }
}
class Program
{
static void Main(string[] args)
{
var pub = new Publisher();
pub.OnChange += (sender, e) => Console.WriteLine($"Event raised: {e.Value}");
pub.OnChange += (sender, e) => Console.WriteLine($"Event raised: {e.Value}");
pub.Raise();
Console.ReadKey();
}
}
public class Publisher
{
public event EventHandler<MyArgs> OnChange = delegate { };
public void Raise()
{
OnChange(this, new MyArgs("FIIIRED!"));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment