473,498 Members | 1,875 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

private new void

Hi,

I have seen some code recently that had the following method
signatures:

private new void Push(object o)

And

public new objectname FunctionName()

So my question is what is happening here? With the first one why would
new be with a void return type? With the second one I am assuming that
the function would return a new object of that type, correct?

JJ

Dec 21 '05 #1
4 7886
JJ,

In this case, the new is not related to the return type of the method.
Rather, new is used to indicate that the method shadows a method with the
same signature declared on the base class.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

<jj****@hotmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
Hi,

I have seen some code recently that had the following method
signatures:

private new void Push(object o)

And

public new objectname FunctionName()

So my question is what is happening here? With the first one why would
new be with a void return type? With the second one I am assuming that
the function would return a new object of that type, correct?

JJ

Dec 22 '05 #2
>So my question is what is happening here?

The new modifier makes it explicit that you want your method to not
override a virtual method with the same name and signature in a base
class, but rather hide it. See
http://msdn.microsoft.com/library/en...lrfnewoppg.asp
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Dec 22 '05 #3
Ah it says use me instead of the one in the base call when called upon?

JJ

Dec 22 '05 #4
<jj****@hotmail.com> wrote:
Ah it says use me instead of the one in the base call when called upon?


Not quite. It says "this is actually a different method which happens
to have the same name, it's not trying to override another method".

See http://www.pobox.com/~skeet/csharp/faq/#override.new

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Dec 22 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
21367
by: Rajesh Garg | last post by:
Can we have private constructors and destructors? IF yes what is the use of such constructors or destructors.....in the sense where can these be implemented in a system................. I have...
8
6813
by: Dave | last post by:
Hello all, Suppose that derived inherits privately from base. A base pointer may not be made to point at a derived object in this case. I understand that is exactly what is supposed to happen...
3
2299
by: quo | last post by:
two questions: 1) Does this program demonstrate the basic difference between public and private access? It appears correct to say that instances of a class cannot directly call a private...
19
2309
by: qazmlp | last post by:
class base { // other members public: virtual ~base() { } virtual void virtualMethod1()=0 ; virtual void virtualMethod2()=0 ; virtual void virtualMethod3()=0 ;
12
3212
by: Bryan Parkoff | last post by:
CMain Class is the base class that is initialized in main function. CA Class is the base class that is initialized in CMain::CMain(). CMain Class is always public while CA Class is always...
6
9996
by: Geoffrey S. Knauth | last post by:
It's been a while since I programmed in C++, and the language sure has changed. Usually I can figure out why something no longer compiles, but this time I'm stumped. A friend has a problem he...
6
1544
by: WXS | last post by:
I know this sounds contrary to the idea of an interface, but read this and see what you think. ----------------------------------------------------------------------------------------- It would be...
6
2257
by: zfareed | last post by:
Is it possible to print an array that is declared from a class type that also contains private data members? I have declared an array in the main function and then set the values for the array...
4
1798
by: zhangyefei.yefei | last post by:
i read book <effective c++>,it tell me that public inheritance means is-a ,and private inheritance means is-implemented-in-terms-of. but today i am puzzled by some strange codes. the...
0
7004
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
7167
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,...
1
6890
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...
0
7379
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...
1
4915
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...
0
3095
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...
0
1423
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 ...
1
657
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
292
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...

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.