- C# 7 and .NET Core 2.0 High Performance
- Ovais Mehboob Ahmed Khan
- 112字
- 2021-08-27 18:47:10
Constant pattern
A constant pattern is a simple pattern that checks for the constant value. Consider the following example: if the Person object is null, it will return and exit the body method.
The Person class is as follows:
class Person { public int ID { set; get; } public string Name { get; set; } public DateTime DOB { get; set; } }
In the preceding code snippet, we have a Person class that contains three properties, namely ID, Name, and DOB (Date of Birth).
The following statement checks for the person object with a null constant value and returns it if the object is null:
if (person is null) return;