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

Difference between C#'s "new" keyword and VB.NET's "shadows" keyword

P: n/a
I need VB.NET's "shadows" functionality inside a C# project.

I tried the "new" keyword, but it didn't seem to work, because my
particular function does in fact differ in signature to the function
that is being hidden in the base class.

In VB.NET, the shadows keyword hides all the inherited functions,
regardless of signature.

I need this functionality in C#.

I'm sure there's an easy way around this, but I am a VB.NET
programmer, and not a C# programmer.

Please C# experts, can you advise me...

TIA,
-dnw.
Nov 16 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
Dot net work wrote:
I need VB.NET's "shadows" functionality inside a C# project.


There is no real equivalent...

See: Equvalent of "Shadows" in VB.Net?
http://www.developersdex.com/csharp/...1111&r=4403835

--
Greetings
Jochen

Do you need a memory-leak finder ?
http://www.codeproject.com/tools/leakfinder.asp

Do you need daily reports from your server?
http://sourceforge.net/projects/srvreport/
Nov 16 '05 #2

P: n/a
Thanks for that thread url.
-dnw.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #3

P: n/a
Dot net work wrote:
I need VB.NET's "shadows" functionality inside a C# project.

I tried the "new" keyword, but it didn't seem to work, because my
particular function does in fact differ in signature to the function
that is being hidden in the base class.

In VB.NET, the shadows keyword hides all the inherited functions,
regardless of signature.

I need this functionality in C#.

I'm sure there's an easy way around this, but I am a VB.NET
programmer, and not a C# programmer.


Even though shadows seems to hide it, it isn't hidden. Everyone can reach
the base class methods through reflection.

FB
--
Get LLBLGen Pro, productive O/R mapping for .NET: http://www.llblgen.com
My .NET Blog: http://weblogs.asp.net/fbouma
Microsoft C# MVP
Nov 16 '05 #4

P: n/a
Hello Frans,
Even though shadows seems to hide it, it isn't hidden. Everyone
can reach
the base class methods through reflection.


Through reflection you can also reach private members...
But you are right.
"shadows" is only a feature of Intellisence of VB.NET!!!

If you use this class in C#, you can see all members!!!
Here is a small example:

<code_vb>
Public Class Test1
Public Function F1()
End Function

Public Function F1(ByVal a As Boolean) As Long
End Function

Public Function F1(ByVal b As Int16, ByVal c As Long) As Boolean
End Function
End Class

Public Class Test2
Inherits Test1

Public Shadows Function F1(ByVal d As Double) As Double
End Function

End Class
</code_vb>
In VB.NET you will see only the Test2.F1 (via Intellisense)!
But you can also call all methods from Test1-class !!! You put the
correct parameters and it will call the method (of course, it is not
supported by intellinsense!).
Also in C#, here you will see all 4 methods via intellisense.

--
Greetings
Jochen

Do you need a memory-leak finder ?
http://www.codeproject.com/tools/leakfinder.asp

Do you need daily reports from your server?
http://sourceforge.net/projects/srvreport/
Nov 16 '05 #5

P: n/a
Dot net work wrote:
I need VB.NET's "shadows" functionality inside a C# project.


"new" is exactly the same as "shadows". But it seems to be a bug in
intellisense that it hides ALL functions with the same name.

If you use an VB.NET library in C# you will see all functions correctly.

--
Greetings
Jochen

Do you need a memory-leak finder ?
http://www.codeproject.com/tools/leakfinder.asp

Do you need daily reports from your server?
http://sourceforge.net/projects/srvreport/
Nov 16 '05 #6

P: n/a
> In VB.NET you will see only the Test2.F1 (via Intellisense)!
But you can also call all methods from Test1-class !!!


Of course, you cannot call it, sorry, for the misleading sentence...
But you can call it from any other language; so it is kind of "very
special" for VB.NET...
--
Greetings
Jochen

Do you need a memory-leak finder ?
http://www.codeproject.com/tools/leakfinder.asp

Do you need daily reports from your server?
http://sourceforge.net/projects/srvreport/
Nov 16 '05 #7

P: n/a
Indeed - VB.NET seems kind of special in this case.
I like this extra functionality for the shadows keyword inside VB.NET.
("shadows" and "new" are not the same.)

I like the ability to hide base class methods, because it provides
less confusion/ambiguity for the calling code.

I tried a simple experiment in VB.NET, and the shadows keyword makes
it impossible to access base class members through simple use of
object.method calling syntax. The editor highlights the problem, and
if you go ahead and run the code anyway, it just calls the inherited
method, and not the base class method. The calling code knows nothing
about the base class method/s. (Naturally, we are talking about
methods whose names are the same, but differ in signature.)

-dnw.

Jochen Kalmbach <no********************@holzma.de> wrote in message news:<Xn**********************************@207.46. 248.16>...
In VB.NET you will see only the Test2.F1 (via Intellisense)!
But you can also call all methods from Test1-class !!!


Of course, you cannot call it, sorry, for the misleading sentence...
But you can call it from any other language; so it is kind of "very
special" for VB.NET...
--
Greetings
Jochen

Do you need a memory-leak finder ?
http://www.codeproject.com/tools/leakfinder.asp

Do you need daily reports from your server?
http://sourceforge.net/projects/srvreport/

Nov 16 '05 #8

P: n/a
Hello Dot net work;
Indeed - VB.NET seems kind of special in this case.
I like this extra functionality for the shadows keyword inside VB.NET.
("shadows" and "new" are not the same.)
Indeed, "shadows" and "new" IS tha same (at least from CLR perspective),
but VB.NET does some "special treatment" if it is a VB.NET-assembly...
I like the ability to hide base class methods, because it provides
less confusion/ambiguity for the calling code.

I tried a simple experiment in VB.NET, and the shadows keyword makes
it impossible to access base class members through simple use of
object.method calling syntax. The editor highlights the problem, and
if you go ahead and run the code anyway, it just calls the inherited
method, and not the base class method. The calling code knows nothing
about the base class method/s. (Naturally, we are talking about
methods whose names are the same, but differ in signature.)


Yes, but this is ONLY true for VB.NET. If you use this assembly in an other
languange (like C#) you can call all methodes...

--
Greetings
Jochen

Do you need a memory-leak finder ?
http://www.codeproject.com/tools/leakfinder.asp

Do you need daily reports from your server?
http://sourceforge.net/projects/srvreport/
Nov 16 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.