IT Community - Software Programming, Web Development and Technical Support

Difference between New and Override keywords

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 ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Software Development > C# Programming

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 05-08-2007, 04:38 AM
raja raja is offline
D-Web Trainee
 
Join Date: May 2007
Posts: 34
raja is on a distinguished road
Post Difference between New and Override keywords

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
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 08-17-2007, 04:34 AM
S.Vinothkumar S.Vinothkumar is offline
D-Web Genius
 
Join Date: May 2007
Posts: 1,061
S.Vinothkumar is on a distinguished road
Smile Re: Difference between New and Override keywords

"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!
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 08-17-2007, 04:52 AM
krishnakumar krishnakumar is offline
D-Web Analyst
 
Join Date: May 2007
Posts: 206
krishnakumar is on a distinguished road
Default Re: Difference between New and Override keywords

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
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


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 Google 1 03-28-2007 06:12 AM


All times are GMT -7. The time now is 04:50 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0