July 2015
Intermediate to advanced
1300 pages
87h 27m
English
To instantiate and consume generic types, you pass to the constructor the type you want to be handled. For example, the following code creates a new instance of the CustomType class, enabling it to handle only integers or types that are converted to Integer via a widening conversion:
Dim integerCollection As New CustomType(Of Integer)(2)integerCollection.Add(0)integerCollection.Add(1)'Writes 1Console.WriteLine(integerCollection(1).ToString)
You pass the desired type to the constructor after the Of keyword. When invoking the Add method, you can notice how IntelliSense tells you that the method can receive only Integer (see Figure 14.1).
FIGURE 14.1 IntelliSense shows what type is accepted ...