试下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" => "洛阳",
                _ => "其他地区"
            };
    }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM