Looking at the TestType
method on the previous page, you may be concerned about runtime type checking and possible boxing and unboxing concerns. Starting with C# 7.1, you can alleviate those concerns using generics.
Beginning with C# 7.1, the pattern expression for is and the switch type pattern may have the type of a generic type parameter. This can be most useful when checking types that may be either struct or class types, and you want to avoid boxing.
Modify the declaration of TestType
so it is a generic method:
public static void TestType<T>(T obj)
The test code follows.