February 2019
Beginner
694 pages
18h 4m
English
To use an instance of this generic class, we need to construct the class and tell the compiler via the < > syntax what the actual type of T is. We can use any type for the type of T in this generic syntax, including base types, classes, or even interfaces. Let's create a few versions of this class, as follows:
var stringConcat = new Concatenator<string>(); var numberConcat = new Concatenator<number>();
Notice the syntax that we have used to instantiate the Concatenator class. On the first line of this sample, we create an instance of the Concatenator generic class, and specify that it should substitute the generic type, T, with the type string in every place where T is being used within the code. Similarly, the ...
Read now
Unlock full access