473,405 Members | 2,444 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Declaring Sub

Hi all,

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

Thanks in advance,

Fabop
Nov 20 '05 #1
3 1574
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: arekkusu | last post by:
Hello, I have the following problem: when declaring hex data in C, you typically do something like: const char = {0xde, 0xad, 0xbe, 0xef, 0x01, 0x02, 0x03, 0x04 ... }; This is quite verbose...
1
by: Maarten Terlingen | last post by:
Sample: ClassA: ClassB ClassB: ClassC ClassA x = new Class C I want to know the declaring type of C. x.GetType() returns C x.GetType().BaseType returns B x.GetType().BaseType.BaseType...
3
by: mark | last post by:
When I declare an array as double(,) then try to use it I get an error: "Object reference not set to an instance of an object." I have found that I can redim the array and all is well. Is my...
1
by: John Dann | last post by:
Is there a way of declaring an array of a structure where the structure has a constructor? So if I had a structure say Friend MyStructure prop1 as integer prop2 as string sub New (p1 as...
5
by: param | last post by:
Declaring struct as static is creating problem with newer version of CC compiler 5.7 in solaris. e.g. static struct new_str { int a; int b; };
4
by: GnG | last post by:
Hello all, Someone posted a similar question a while ago but there was no response. Does anyone know the answer? I have a managed C++ DLL which is used by a C# project. In that DLL, I have...
6
by: Mark A. Sam | last post by:
Hello, I am using Visual Web Developer 2005 Express. I want to declare a varible, using Visual Basic as the language and can't get anywhere. For example Public Test1 as String I'll get en...
8
by: rendle | last post by:
I have a MSIL/performance question: Is there any difference between declaring a variable once and assigning to it multiple times, and declaring and assigning multiple times? For example: //...
8
by: SM | last post by:
I've always wonder if there is diference when declaring and initializing a varible inside/outside a loop. What's a better practice? Declaring and initializing variables inside a loop routine,...
8
by: nguillot | last post by:
Hello. If I have the following classes: class B {}; typedef B tB; if A is: class A
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.