Last active
August 29, 2015 13:57
-
-
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#.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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