- C# 7 and .NET Core Cookbook
- Dirk Strauss
- 212字
- 2021-07-03 00:11:52
How it works...
With pattern matching, we saw that patterns are used to test whether a value is of a certain type.
You will also hear some developers say that they test whether the value has a certain shape.
When we find a match we can get to the information specific to that type (or shape). We saw this in the code where we accessed the CourseCodes property, which was specific to the Student type and the TeachesSubjects property, which was specific to the Professor type.
Lastly, you now need to pay careful attention to the order of your case statements, which now matters. The case statement that uses the when clause is more specific than the statement that simply checks for a Student type. This means that the when case needs to happen before the Student case because both of these cases are of type Student. If the Student case happens before the when clause, it will never trigger the switch for Students that have course code 203.
Another important thing to remember is that the default clause will always be evaluated last, irrespective of where it appears in the switch statement. It is, therefore, good practice to write it as the last clause in a switch statement.
- Instant Zepto.js
- HTML5 Mobile Development Cookbook
- 實用防銹油配方與制備200例
- 前端架構:從入門到微前端
- Python Data Analysis(Second Edition)
- 量化金融R語言高級教程
- Go并發編程實戰
- 飛槳PaddlePaddle深度學習實戰
- Getting Started with LLVM Core Libraries
- Multithreading in C# 5.0 Cookbook
- AutoCAD 2009實訓指導
- 數據科學中的實用統計學(第2版)
- Python預測之美:數據分析與算法實戰(雙色)
- Data Manipulation with R(Second Edition)
- Python編程入門(第3版)