Skip to content

Instantly share code, notes, and snippets.

@fredyfx
Last active November 29, 2019 22:46
Show Gist options
  • Save fredyfx/c87282bf269024a3f9a410097b9d5360 to your computer and use it in GitHub Desktop.
Save fredyfx/c87282bf269024a3f9a410097b9d5360 to your computer and use it in GitHub Desktop.
// nasty..
switch(MyObj.GetType.ToString()){
case "Type1": etc
}
// clumsy...
if myObj is Type1 then
if myObj is Type2 then
var @switch = new Dictionary<Type, Action> {
{ typeof(Type1), () => ... },
{ typeof(Type2), () => ... },
{ typeof(Type3), () => ... },
};
@switch[typeof(MyType)]();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment