Purpose of Keyword "Overloads"?

  • Thread starter Thread starter Arthur Dent
  • Start date Start date
A

Arthur Dent

Hi all,

Im just curious, what is the purpose of the keyword "Overloads" in VB
nowadays?
I understand conceptually what overloads are and what they do, but im a
little puzzled,
because if you declare two subs or properties or functions with the same
name but
different signatures, it seems to overload them without any problem anyway,
so why
is the keyword there?
Does using the keyword just work as some sort of compiler hint or something
or ?

Cheers!
- Arthur Dent.
 
Vijay said:
Its just there... a optional use... no big deal if you use it or if you
don't...

IIRC 'Overloads' is not always optional (see documentation).
 
Here's a simple example on where teh Overloads keyword is necessary:

Public MustInherit Class Class1

Public MustOverride Sub Method1()
Public MustOverride Sub Method1(ByVal x As Integer)
Public MustOverride Sub Method1(x as Integer, y as String

End Class

Public Class Class2
Inherits Class1

Public Overloads Overrides Sub Method1()

End Sub

Public Overloads Overrides Sub Method1(ByVal x As Integer)

End Sub

Public Overloads Overrides Sub Method1(ByVal x As Integer, ByVal y As
String)

End Sub
End Class

In the "Class2" definition, the "Overloads" keyword is necessary or your
code will not compile.
 
Back
Top