上QQ阅读APP看书,第一时间看更新
Var pattern
The var pattern checks if the var is equal to some type. The following example shows how the var pattern can be used to check for the type and print the Type name:
if (person is var Person) Console.WriteLine($"It is a person object and type is {person.GetType()}");
To learn more about patterns, you can refer to the following link: https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-7#pattern-matching.