This is a discussion on Difference between New and Override keywords within the C# Programming forums, part of the Software Development category; new Modifier (C#) The new modifier instructs the compiler to use your implementation instead of the base class implementation. Any ...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| new Modifier (C#) The new modifier instructs the compiler to use your implementation instead of the base class implementation. Any code that is not referencing your class but the base class will use the base class implementation. override (C#) The override modifier may be used on virtual methods and must be used on abstract methods. This indicates for the compiler to use the last defined implementation of a method. Even if the method is called on a reference to the base class it will use the implementation overriding it. public class A { public virtual void One(); public void Two(); } public class B : A { public override void One(); public new void Two(); } B b = new B(); A a = b as A; a.One(); // Calls implementation in B a.Two(); // Calls implementation in A b.One(); // Calls implementation in B b.Two(); // Calls implementation in B |
| Sponsored Links |
| |||
| "Override" keyword is used for function when we provide different definition to base class function in derived class. "New" keyword is used for allocate memory to variable.
__________________ S.VinothkumaR Behind me is infinite power, Before me is Endless Possibility, Around me is Boundless Opportunity, Why should I fear! |
| |||
| Hi, Can u clear me by any sample codings to differentiate the new and override keywords
__________________ Krishnakumar.S Beware of Everything -that is un true; stick to the Truth shall succeed slowly but steadily |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Is it possible to override a method in Partial class ? | oxygen | ASP and ASP.NET Programming | 2 | 02-08-2008 02:47 AM |
| shadow and override | sivakumar | C# Programming | 2 | 08-17-2007 05:58 AM |
| Shadow and override | vigneshgets | C# Programming | 2 | 08-16-2007 10:36 PM |
| I wonder how they collect these keywords. | montyauto | The Lounge | 0 | 05-29-2007 05:17 AM |
| Grouping PPC Keywords? | montyauto | 1 | 03-28-2007 06:12 AM | |