using “new” in a method definition. I don’t quite understand it.
Question:
My co-worker brought the following link to my attention.
http://www.codeproject.com/csharp/csharpintro01.asp
He asked me what the following is forĀ (in the Dog class)
public new void Talk()
{
Console.WriteLine(“Dog talk”);
}
He was asking what new meant in the method definition. I’m not entirely sure… what can you do with this that you can’t do with overriding a virtual method? What is this used for.
Solution:
There isn’t a huge difference…
http://msdn2.microsoft.com/en-us/library/435f1dw2.aspx
the new keyword explicitly hides a member inherited from a base class. Hiding an inherited member means that the derived version of the member replaces the base-class version. Hiding members without the use of the new modifier is allowed, but generates a warning.
http://msdn2.microsoft.com/en-us/library/ebca9ah3.aspx
The override modifier is required to extend or modify the abstract or virtual implementation of an inherited method, property, indexer, or event.
Here is a good example:
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=520024&SiteID=1













Comments (0)
Trackbacks - Pingbacks (0)
Leave a Reply