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