Skip to content

Instantly share code, notes, and snippets.

@luisdeol
Created January 7, 2018 22:58
Show Gist options
  • Save luisdeol/38790cb6c31253d1d338e7c498adeee2 to your computer and use it in GitHub Desktop.
Save luisdeol/38790cb6c31253d1d338e7c498adeee2 to your computer and use it in GitHub Desktop.
Raising an event using Action delegate
using System;
namespace create_implement_events_callbacks
{
class Program
{
static void Main(string[] args)
{
var publisher = new Publisher();
publisher.OnChange += () => Console.WriteLine("Merry Christmas!");
publisher.OnChange += () => Console.WriteLine("Happy New Year");
publisher.Raise();
Console.ReadKey();
}
}
public class Publisher
{
public Action OnChange { get; set; }
public void Raise()
{
OnChange?.Invoke();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment