Click to See Complete Forum and Search --> : rg, i give up, C# question, diff between new and override w/ overriding methods?


Mancora
06-26-2005, 04:43 PM
In looking over examples ive noticed that there seem to be two different ways to have a method with the same name in the child class and parent class. Ya ya, over riding the parent method, but two ways? and they seem to act different as well. Due to the fact that "new" is used when ever an object is created actually finding any info out on this has been pretty hard.


just so we're all on the same page, here are the two methods

protected override void OnPaint(PaintEventArgs pea) {...}
protected new void OnPaint(PaintEventArgs pea) {...}


From testing ive noticed that when i use "new" and execute the method in the child class code from the parent class is executed, and when i use "override" and execute the method in the chile class code from the child class is used.

So using the "override" keyword does what i would expect, it overrides the method.

What then, does the "new" keyword do in this case?

Mancora
06-26-2005, 06:44 PM
I finally found my way though the MSDN to the info

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csref/html/vclrfnewoppg.asp