Creating a generic class works the same as creating a non-generic class but with one important difference: its generic type parameter. Let's take a look at an example of a generic collection class we might want to create to get a clearer picture of how this works:
public class SomeGenericCollection<T> {}
We've declared a generic collection class named SomeGenericCollection and specified that its type parameter will be named T. Now, T will stand in for the element type that the generic list will store and can be used inside the generic class just like any other type.
Whenever we create an instance of SomeGenericCollection, we need to specify the type of values it can store:
SomeGenericCollection<int> highScores = new SomeGenericCollection<int>
();
In this case, highScores stores integer values and T stands in for the int type, but the SomeGenericCollection class will treat any element type the same.Â