10.9. Overloaded Types and MembersNormally, you can only create a single definition of a named class within a namespace. However, you can create multiple class definitions with the same name if they each include a different number of type parameters (zero or more). The following statements define two distinct classes that share a common name. Public Class OverloadedName(Of T1) End Class Public Class OverloadedName(Of T1, T2) End Class The compiler will use the appropriate class definition, depending on the number of type parameters supplied when instantiating that class name. ' ----- The compiler will use the (Of T1) definition. Dim justOne As OverloadedName(Of Integer) Methods can be overloaded in the same way. This type of overloading can be mixed with the standard method of overloading. Public Sub DoSomeWork(Of T)(ByVal data1 As T) End Sub Public Sub DoSomeWork(Of T)(ByVal data1 As T, data2 As String) End Sub Public Sub DoSomeWork(Of T1, T2)(ByVal data1 As T1, _ ByVal data2 As T2) End Sub |