Hi,
I am newbie to VB.NET.
Kindly explain me what is overloading and overriding
in vb.net.How this can be achieved.
Please explain with some good examples.
So I will have a clear idea.
Thanks and regards
bali
Printable View
Hi,
I am newbie to VB.NET.
Kindly explain me what is overloading and overriding
in vb.net.How this can be achieved.
Please explain with some good examples.
So I will have a clear idea.
Thanks and regards
bali
Overloading is basically when you have more than one method with the same name but a different number of or different types of parameters. The application then determines which one to call based on the parameters used. Showing the 'Overloads' keyword is optional as long as all of the methods either use it or don't use it.
VB Code:
'will work Public Sub Testing() 'code here End Sub Public Sub Testing(ByVal Filename As String) 'code here End Sub 'this will also work Public Overloads Sub Testing() 'code here End Sub Public Overloads Sub Testing(ByVal Filename As String) 'code here End Sub 'but this will not because only one method uses the Overloads keyword Public Sub Testing() 'code here End Sub Public [b]Overloads[/b] Sub Testing(ByVal Filename As String) 'code here End Sub
Overrides is used by derived classes (classes that inherit from a base class) to replace the original method from the base class with one of its own, which must match the same method signature.
VB Code:
'base class Public Class BaseClass Public Overridable Sub Testing() Msgbox("Shown from the Base") End Sub End Class 'derived class Public Class DerivedClass Inherits BaseClass Public Overrides Sub Testing() Msgbox("Shown from the Derived") End Sub End Class 'then in an app Dim bc as New BaseClass() bc.Testing() Dim dc as New DerivedClass() dc.Testing()
I just thought I would let you know Edneeis....
Your knowledge of this subject scares me at times.
P.S
Dont work to hard
;)