By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,605 Members | 1,346 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,605 IT Pros & Developers. It's quick & easy.

Declaring Sub

P: n/a
Hi all,

Whats the real difference between Overloads and Shadows in a Sub????

Thanks in advance,

Fabop
Nov 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Fabio,

an overloads method is the same member type (sub, function, property,
etc...)
a Shadows method has the same name, but is either a diferent member type, or
a function with an incompatible return type.

Basicly, Overloads offers another choice to the developer using the class
(both methods are available), Shadows hides the base class member(only the
Shadows member is available).

Kirk Graves

"Fabio" <fa***@glb.com.br> wrote in message
news:uT**************@TK2MSFTNGP12.phx.gbl...
Hi all,

Whats the real difference between Overloads and Shadows in a Sub????

Thanks in advance,

Fabop

Nov 20 '05 #2

P: n/a
You use Overloads when you want to declare multiple versions of the same
method that take different parameters.
Shadows is used to make you method replace the same one that is implemented
by your base class. In this case your base class did not declare the method
with Overridable (virtual), so you cannot use the Overrides keyword in your
method declaration.
--
TJoker, MCSD.NET
MVP: Paint, Notepad, Solitaire

****************************************
"Fabio" <fa***@glb.com.br> wrote in message
news:uT**************@TK2MSFTNGP12.phx.gbl...
Hi all,

Whats the real difference between Overloads and Shadows in a Sub????

Thanks in advance,

Fabop

Nov 20 '05 #3

P: n/a
Hi Fabio,

Overloading a method allows you to specify multiple versions of the same
method, but with a different parameter signature:

Public Overloads Sub ShowMessge(ByVal Text As String)
'
End Sub

Public Overloads Sub ShowMessage(ByVal Number As Integer)
'
End Sub

Public Overloads Function ShowMessage(ByVal Number As Integer, ByVal Text As
String) As Boolean
'
End Sub

You can overload the return type of a method, as long as the parameters are
different to any other overloaded version.

Shadowing isn't *really* related to Overloading (perhaps you meant
overriding?), however it is linked due to the fact that you can overload a
version of a method in a base class, with a new version in the derived class

Public Class MyBaseClass
Public Sub MySub()
'
End Sub
End Class

Public Class MyDerivedClass
Inherits MyBaseClass

Public Shadows Function MySub(Argument As String) As Integer
'
End Sub
End Class

* or *

Public Class MyBaseClass
Public Sub MySub()
'
End Sub
End Class

Public Class MyDerivedClass
Inherits MyBaseClass

Public Overloads Function MySub(Argument As String) As Integer
'
End Sub
End Class

They are both valid because the parameters are different.

The shadows clause, when attached to a method declaration allows you to
replace a method that's declared in a base class, with a new version, in the
new class. It does not override the base method, and so you can specify a
different access level, or return type, or parameters. This means you can
create a new version of a method that replaces a method in the base class
that is not declared as overridable.

--
HTH,
-- Tom Spink, Über Geek

Please respond to the newsgroup,
so all can benefit

" System.Reflection Master "

==== Converting to 2002 ====
Remove inline declarations
"Fabio" <fa***@glb.com.br> wrote in message
news:uT**************@TK2MSFTNGP12.phx.gbl...
Hi all,

Whats the real difference between Overloads and Shadows in a Sub????

Thanks in advance,

Fabop

Nov 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.