Skip to content

Instantly share code, notes, and snippets.

@dchw
Last active August 29, 2015 13:57
Show Gist options
  • Save dchw/9636537 to your computer and use it in GitHub Desktop.
Save dchw/9636537 to your computer and use it in GitHub Desktop.
Using the 'switch' keywords as a descriptive way to fake switching on types in C#.
var @switch = new Dictionary<Type, Action>
{
{typeof(CSharp), () =>
{
Console.WriteLine("<3");
}},
{typeof(Rainbow), () =>
{
Console.WriteLine("20% Cooler");
}},
{typeof(MtnDew), () =>
{
Console.WriteLine("God's Nectar");
}},
{typeof(Pencil), () =>
{
Console.WriteLine("Like a pen, but you can erase it!");
}},
};
//Actually do the switch
@switch[typeof(Pencil)]();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment