//switch(i) {
// case 1: Foo(); break;
// case 2: Bar(); break;
// default: throw new Exception("unexpected");
//}
var lookup = new Dictionary<int, Action>() { {1, Foo}, {2,Bar} };
if (!lookup.ContainsKey(i)) {
throw new Exception("unexpected");
}
lookup[i]();