Skip to content

Instantly share code, notes, and snippets.

@qassa
Created October 12, 2018 18:04
Show Gist options
  • Save qassa/05ea3ad39589578431b3c880736145b5 to your computer and use it in GitHub Desktop.
Save qassa/05ea3ad39589578431b3c880736145b5 to your computer and use it in GitHub Desktop.
short ways
using System;
using System.Collections.Generic;
namespace SharpDelegateSwitch
{
class Program
{
static void Main(string[] args)
{
Dictionary<int, Action> vars = new Dictionary<int, Action>();
vars.Add(1, () => { /*Console.WriteLine("1 was generated");*/ });
vars.Add(2, () => { });
vars.Add(3, () => { });
vars.Add(4, () => { });
vars.Add(5, () => { });
Random r = new Random();
Action ac = vars[r.Next(1, 5)];
ac();
switch (r.Next(1, 5))
{
case 1:
break;
case 2:
break;
case 3:
break;
case 4:
break;
case 5:
break;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment