最近在使用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中又有增強。
https://docs.microsoft.com/zh-cn/dotnet/csharp/whats-new/csharp-8#more-patterns-in-more-places