473,387 Members | 1,619 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,387 software developers and data experts.

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 13283
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**********************************@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
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
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...
10
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...
9
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...
10
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
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...
5
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...
41
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...
11
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 !! ...
7
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,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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,...
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
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,...

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.