C#7.0模式匹配

            var str = "abcDEF";
            switch (str)
            {
                case string x when x.StartsWith("abc"):
                    Console.WriteLine("abc");
                    break;
                case string x when x.StartsWith("efc"):
                    Console.WriteLine("efc");
                    break;
            }
            Console.Read();
        }

 

posted @ 2022-02-24 14:54  江境纣州  阅读(32)  评论(0编辑  收藏  举报