C# 模式匹配


 最近在使用vs编码时,重构提示:模式匹配

Element view = bindable as Element;
            if (view == null)
            {
                return;
            }

运用模式匹配可以简写为:

 if (!(bindable is Element view))
            {
                return;
            }

模式匹配在C# 7.0中引入

https://docs.microsoft.com/zh-cn/dotnet/csharp/whats-new/csharp-7#pattern-matching

在8.0中又有增强。 

C# 8.0中的模式匹配

https://docs.microsoft.com/zh-cn/dotnet/csharp/whats-new/csharp-8#more-patterns-in-more-places

 


免责声明!

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



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