试下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 @ 2022-03-21 13:39  星畔  阅读(107)  评论(0编辑  收藏  举报