473,666 Members | 2,386 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 13293
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
1907
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
3217
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
6101
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
3027
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
1795
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
1669
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
4288
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
2697
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
1811
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
8440
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
8866
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8550
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8638
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5662
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
4193
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2769
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
2006
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1769
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.