試下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