using System.Collections.Generic;
public static void Main()
var keyHandlers = new Dictionary<int, Action>();
keyHandlers.Add(0, () => Console.WriteLine("Handler for 0"));
keyHandlers.Add(2, () => {
Console.WriteLine("Handled 2: value{0}", y);
keyHandlers.Add(3, PrintHello);
for( int i = 0; i < 5; i++)
Console.WriteLine("Event number:{0}", i);
bool actionRegistered = keyHandlers.TryGetValue(i, out actionToDo);
Console.WriteLine(" Action was registered");
public static void PrintHello()
Console.WriteLine("Hello World");