试下C# 8.0 的switch表达式 (VS2019)

class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            Console.WriteLine(TestSwitch("0371"));
            Console.WriteLine(TestSwitch("071"));
            Console.ReadKey();
        }

        public static string TestSwitch(string code) =>
            code switch
            {
                "0371" => "郑州",
                "0378" => "开封",
                "0379" => "洛阳",
                _ => "其他地区"
            };
    }

 

posted @ 2020-04-16 10:06  向萧  阅读(2868)  评论(2编辑  收藏  举报