if..else的替换
if..else的替换:
public static void Sample(string item) { System.Collections.Generic.Dictionary<string, Action> dic = new System.Collections.Generic.Dictionary<string, Action>(1); dic.Add("0", () => { Console.WriteLine("0"); }); dic.Add("1", () => { Console.WriteLine("1"); }); dic.Add("2", () => { Console.WriteLine("2"); }); dic[item].Invoke(); }