C# - Get Switch Value If In Default Case
Answer : Is there a way to get the switch value from inside a case? The only (proper) way is actually to store the result of MyFoo() in a variable. var fooResult = MyFoo(); switch (fooResult) { case 0: ... break; ... default: handleOthersCase(fooResult); break; } This code is readable and understandable and have no extra cost (As @SheldonNeilson says: It's on the stack anyway). Also, the MSDN first example about switch totally look like this. You can also find informations int the language specification. You also can make your own switch based on a dictionary, but the only advantage I see is that you can use it for complex cases (any kind of object instead of string/int/...). Performance is a drawback. It may look like this: public class MySwitch<T> : Dictionary<T, Action<T>> { private Action<T> _defaultAction; public void TryInvoke(T value) { Action<T> action; ...