- 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.
推薦閱讀
- 同步:秩序如何從混沌中涌現(xiàn)
- 使用GitOps實現(xiàn)Kubernetes的持續(xù)部署:模式、流程及工具
- SQL Server 2008數(shù)據(jù)庫應(yīng)用技術(shù)(第二版)
- 圖解機器學(xué)習(xí)算法
- Live Longer with AI
- 數(shù)據(jù)挖掘原理與SPSS Clementine應(yīng)用寶典
- Starling Game Development Essentials
- 探索新型智庫發(fā)展之路:藍迪國際智庫報告·2015(下冊)
- 新手學(xué)會計(2013-2014實戰(zhàn)升級版)
- Unity 2018 By Example(Second Edition)
- 實現(xiàn)領(lǐng)域驅(qū)動設(shè)計
- 基于數(shù)據(jù)發(fā)布的隱私保護模型研究
- 數(shù)據(jù)庫技術(shù)與應(yīng)用:SQL Server 2008
- 數(shù)據(jù)時代的品牌智造
- Managing Software Requirements the Agile Way