How to do it...

  1. Declaring a generic class is actually very easy. All that we need to do is create the class with the generic type parameter <T>:
        public class PerformAction<T>         {         }
The generic type parameter is basically a placeholder for a specific type that will need to be defined when the class of variable is instantiated. This means that the generic class PerformAction<T> can never just be used without specifying the type argument inside angle brackets when instantiating the class.
  1. Next, create a private variable of the generic type parameter T. This will hold the value we pass to the generic class:
        public class PerformAction<T>         {           private T _value;         }
  1. We now need to add a constructor to the generic class. The constructor will ...

Get C# 7 and .NET Core Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.