rg, i give up, C# question, diff between new and override w/ overriding methods?

Sharky Forums


Results 1 to 2 of 2

Thread: rg, i give up, C# question, diff between new and override w/ overriding methods?

  1. #1
    Mako Shark Mancora's Avatar
    Join Date
    Jun 2001
    Location
    The other side of where the fishes swim
    Posts
    4,313

    rg, i give up, C# question, diff between new and override w/ overriding methods?

    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?
    Last edited by Mancora; 06-26-2005 at 04:45 PM.

  2. #2
    Mako Shark Mancora's Avatar
    Join Date
    Jun 2001
    Location
    The other side of where the fishes swim
    Posts
    4,313
    I finally found my way though the MSDN to the info

    http://msdn.microsoft.com/library/de...lrfnewoppg.asp
    Last edited by Mancora; 06-26-2005 at 06:56 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •