Section 10.9. Overloaded Types and Members


10.9. Overloaded Types and Members

Normally, 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 




Visual Basic 2005(c) In a Nutshell
Visual Basic 2005 in a Nutshell (In a Nutshell (OReilly))
ISBN: 059610152X
EAN: 2147483647
Year: 2004
Pages: 712

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net