- C# 7 and .NET Core 2.0 High Performance
- Ovais Mehboob Ahmed Khan
- 102字
- 2021-08-27 18:47:10
Type pattern
The type pattern can be used with an object to verify whether it matches the type or suffices the expression based on the conditions specified. Suppose we need to check whether the PersonID is int; assign that ID to another variable, i, and use it in the program, otherwise return:
if (!(person.ID is int i)) return; Console.WriteLine($"Person ID is {i}");
We can also use multiple logical operators to evaluate more conditions, as follows:
if (!(person.ID is int i) && !(person.DOB>DateTime.Now.AddYears(-20))) return;
The preceding statement checks whether the Person.ID is null or not and whether the person is older than 20.
推薦閱讀
- PyTorch深度學(xué)習(xí)實戰(zhàn):從新手小白到數(shù)據(jù)科學(xué)家
- Architects of Intelligence
- Redis應(yīng)用實例
- 分布式數(shù)據(jù)庫系統(tǒng):大數(shù)據(jù)時代新型數(shù)據(jù)庫技術(shù)(第3版)
- 數(shù)據(jù)結(jié)構(gòu)與算法(C語言版)
- iOS and OS X Network Programming Cookbook
- 數(shù)據(jù)要素五論:信息、權(quán)屬、價值、安全、交易
- 數(shù)據(jù)驅(qū)動設(shè)計:A/B測試提升用戶體驗
- 大數(shù)據(jù)架構(gòu)商業(yè)之路:從業(yè)務(wù)需求到技術(shù)方案
- 數(shù)字IC設(shè)計入門(微課視頻版)
- Hands-On Deep Learning for Games
- 數(shù)據(jù)挖掘與機器學(xué)習(xí)-WEKA應(yīng)用技術(shù)與實踐(第二版)
- 數(shù)據(jù)挖掘算法實踐與案例詳解
- INSTANT Windows Powershell 3.0 Windows management Instrumentation Starter
- 大學(xué)計算機基礎(chǔ)習(xí)題與實驗指導(dǎo)(第2版)