Please let other users know how useful this tip is by rating it below. Do you have a tip or code of your own you'd like to share? Submit it here.
This code demonstrates the use of Function OverLoading, which can prove quite handy when designing commercial and enterprise components.
Imports system
Imports microsoft.visualbasic ' For msgbox
Namespace N1
Class Ovrl
Shared Sub main()
myfunc("Mansih")
myfunc(22)
End Sub
'Accepts Integer
Overloads Shared Function myfunc
(ByVal i As Integer) As String
msgbox("Overloaded Function Accepting Integer")
End Function
'Accepts String
Overloads Shared Function myfunc(ByVal s As String
) As String
msgbox("Overloaded Function Accepting String")
End Function
End Class
End Namespace
The previous example demonstrated Function Overloading. It is also possible to overload a constructor -- it's also one of my favorite features:
Imports system
Imports microsoft.visualbasic ' For msgbox
Namespace N1
Class OvrConst
Shared Sub main()
Dim o As New OvrConst()
Dim x As New OvrConst("Constructor 2")
End Sub
'cosntructor 1 without parameter
Public Overloads Sub New()
msgbox("Constructor 1")
End Sub
'cosntructor 2 with a String parameter
Public Overloads Sub New(ByVal s )
msgbox(s)
End Sub
End Class
End Namespace
Source: DotNetExtreme.com
This was first published in July 2003