473,386 Members | 1,827 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

When to use new and when to use override???

Hello,

it is not clear to me when to use new and when to use override (on a virtual
method). Could someone explain when to use each. Also it is not clear to me
if the hidden or overriden (base) method is still accessible. Thx.

Bob Rock
Nov 16 '05 #1
2 1805
"Bob Rock" <no***************************@hotmail.com> wrote in message
news:Oc*************@TK2MSFTNGP10.phx.gbl...
Hello,

it is not clear to me when to use new and when to use override (on a virtual method). Could someone explain when to use each. Also it is not clear to me if the hidden or overriden (base) method is still accessible. Thx.


Never use "new" on a virtual method. Use "virtual" when introducing the
method (i.e.when no ancestor class defines the same method) and "override"
when overriding it (i.e.when some ancestor class defines the same method,
even abstractly).

The closest ancestor version of the method is accessible using the "base"
keyword. None of the others are.
Nov 16 '05 #2
Bob Rock <no***************************@hotmail.com> wrote:
it is not clear to me when to use new and when to use override (on a virtual
method). Could someone explain when to use each. Also it is not clear to me
if the hidden or overriden (base) method is still accessible. Thx.


See http://www.pobox.com/~skeet/csharp/faq/#override.new

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Tony Johansson | last post by:
Hello experts! I know it's easy to override when you have inheritance. But if you instead use object composition having a pointer to a class X. If you want to override when having this object...
1
by: Thomas | last post by:
Hi, I implemented a composite pattern which should be serializable to xml. After spending some time in the newsgroups, i finally managed serializing, even with utf-8 instead of utf-16, which...
5
by: n_o_s_p_a__m | last post by:
Can't compile. Does this mean that all functions that throw exceptions must be of return type void? examples: // won't compile: "not all code paths return a value" public override int Run() {...
11
by: Noah Coad [MVP .NET/C#] | last post by:
How do you make a member of a class mandatory to override with a _new_ definition? For example, when inheriting from System.Collections.CollectionBase, you are required to implement certain...
2
by: Jaikumar | last post by:
Hi, 1) I have created one windows application, In the main form ( form1) i have added one usercontrol (usercontrol1), In that user control i am drawing one image. 2) In the UserControl1 i am...
10
by: Rigs | last post by:
Hi, I have a textbox with a Custom Validator that utilizes the OnServerValidate method for that textbox. This works fine, however the method only executes when data exists in that textbox after...
8
by: bdeviled | last post by:
I am deploying to a web environment that uses load balancing and to insure that sessions persist across servers, the environment uses SQL to manage sessions. The machine.config file determines how...
8
by: Kenneth Baltrinic | last post by:
When one overrides the Equals() method of an object, one is supposed to override GetHashCode() as well and this makes good sense. But I have seen lots of people who do this and do not override the...
3
by: Allan Ebdrup | last post by:
We're pretty new to ASP.Net 2.0 and we're having a discussion about best practice when developing custom server web controls. I can see that in for example the Wizard control the table contained...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.