Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / December 2005

Tip: Looking for answers? Try searching our database.

private new void

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
jjmraz@hotmail.com - 21 Dec 2005 23:26 GMT
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
Nicholas Paldino [.NET/C# MVP] - 21 Dec 2005 23:50 GMT
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.

Signature

         - Nicholas Paldino [.NET/C# MVP]
         - mvp@spam.guard.caspershouse.com

> Hi,
>
[quoted text clipped - 12 lines]
>
> JJ
jjmraz@hotmail.com - 22 Dec 2005 12:01 GMT
Ah it says use me instead of the one in the base call when called upon?

JJ
Jon Skeet [C# MVP] - 22 Dec 2005 12:25 GMT
> 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

Signature

Jon Skeet - <skeet@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

Mattias Sjögren - 21 Dec 2005 23:52 GMT
>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-us/csref/html/vclrfnewoppg.asp

Mattias

Signature

Mattias Sjögren [C# MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.