471,325 Members | 1,582 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,325 software developers and data experts.

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 7700
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Rajesh Garg | last post: by
8 posts views Thread by Dave | last post: by
3 posts views Thread by quo | last post: by
12 posts views Thread by Bryan Parkoff | last post: by
6 posts views Thread by zfareed | last post: by
4 posts views Thread by zhangyefei.yefei | last post: by
reply views Thread by rosydwin | last post: by

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.