473,898 Members | 4,077 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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
8 13308
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
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
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
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
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
> 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
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******* *************** ************@20 7.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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
1927
by: Ola Johansson | last post by:
Can anyone explain to me a meningfull use of the "new" keyword (Shadows in VB). I think i understand how it works fully but i cant figure out why you would use it. Why would you want to declare a variable in a derived class with the same name as in the base class but with a diffrent meaning? Anyone can think of a scenario for this?
10
3235
by: ÷zden Irmak | last post by:
Hi, I'm trying to hide an event of my custom usercontrol derived control, something like "Shadows" in VB.Net, but although the event is hidden from PropertyGrid, from CodeEditor I can still see/reach it. I use this code :
9
6123
by: Chazza | last post by:
I would like to override a method from an inherited class, but the new method has a different signature to the inherited class. Example: class A { private void Init() { // code } } class B : A {
10
3050
by: Lino Barreca | last post by:
Take a look at this code: Class clsAnagrafica Public Overridable ReadOnly Property Codice() As Integer Get Return 1 End Get End Property End Class
9
1811
by: Larry Woods | last post by:
I have a method in my base class that I want ALL derived classes to use. But, I find that I can create a "Shadow" method in my derived class that "overrides" the method in my base class. Can't figure out what attribute to put on the base class method to prevent this. TIA, Larry Woods
5
1678
by: Dave Taylor | last post by:
I'm trying to derive a class from a typed DataSet to add some methods to one of the DataTables. I would like to keep the names the same in the derived class as in the base class, so I have used "Shadows" to hide the base class members. However, this does not seem to work. Any pointers as to what I'm doing wrong here? (I've attached the basics of the code below). Thanks Dave Taylor
41
4353
by: JohnR | last post by:
In it's simplest form, assume that I have created a usercontrol, WSToolBarButton that contains a button. I would like to eventually create copies of WSToolBarButton dynamically at run time based on some initialization information obtained elsewhere. Basically, I'm going to create my own dynamic toolbar where the toolbarbuttons can change. I'm not using the VB toolbar because of limitations in changing things like backcolor (I can't get...
11
2718
by: fourfires.d | last post by:
Dear All, I am new to c++ and when write below code that try to call copy constructor in "=" operator overloading, it can not compile. Can anyone point out for me the reason? thanks !! class AA {
7
1820
by: Nik Coughlin | last post by:
Further to my earlier post in alt.html, I ended up preparing these pages: http://nrkn.com/skinning/ They list different ways to "skin" an HTML element (ie add rounded corners, drop shadows, various other graphical effects) using images while still allowing for viewport and text re-sizing. Anyone know of any other techniques that I've missed?
0
9993
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
9841
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10858
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8036
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 presenter, Adolph Duprť who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7187
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6077
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4706
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4296
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3306
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.