473,503 Members | 4,272 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

about override

Hello!

I have noticed that you can write this override in two different ways.

You can either write in this way
public override string ToString()
{
return something;
}

OR IN THIS WAY
override public string ToString()
{
return something;
}

Is this two way exactly the same thing?
Which way is the recommnended way?

//Tony



Jul 7 '06 #1
3 1328
Tony

I have never seen the latter way of writing it before you pointed it out, but they are equal. The first way is the preferred, and intellisense will in fact swap the latter with the first, although readability might argue the latter is the better.

--
Happy coding!
Morten Wennevik [C# MVP]
Jul 7 '06 #2
Tony Johansson wrote:
Hello!

I have noticed that you can write this override in two different ways.

You can either write in this way
public override string ToString()
{
return something;
}

OR IN THIS WAY
override public string ToString()
{
return something;
}

Is this two way exactly the same thing?
Which way is the recommnended way?

//Tony
Hi Tony,

If you're a native English speaker, it seems logical to say: "override
public string", since you are going to "override" the method signature that
follows. However, I *always* without question use "public override string"
because it maintains a standard throughout my code, i.e. the method
signature begins with a scope, then any modifiers, then it's return type.

I reccommend the first.

--
Hope this helps,
Tom Spink
Jul 7 '06 #3
They are exactly the same, just the keywords in different sequences.

The convention most everyone uses is :
public override string ToString()

with the access modifier first.

HTH
Gandalf
MCSD.NET, MCAD, MCT
"Tony Johansson" wrote:
Hello!

I have noticed that you can write this override in two different ways.

You can either write in this way
public override string ToString()
{
return something;
}

OR IN THIS WAY
override public string ToString()
{
return something;
}

Is this two way exactly the same thing?
Which way is the recommnended way?

//Tony



Jul 7 '06 #4

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

Similar topics

3
1660
by: Gonçalo Rodrigues | last post by:
Hi all, I have a base class, call it Object, that implements operators new and delete. Now suppose there is also a class, call it Derived, deriving from Object. It has the feature that *all*...
13
4236
by: Stephen Walch | last post by:
Error C2392 is hitting me hard! I have a managed C++ library that implements a bunch of fixed interfaces. For example, one interface is: public abstract interface IDbCommand { public...
7
1692
by: tony | last post by:
Hello! What is the differens if I use event handler onSizeChanged compare to using the other event handler MeltPracForm_SizeChanged. I see both as event handler is that right? I catch the event...
60
4704
by: deko | last post by:
As I understand it, most browser manufacturers have agreed on 16px for their default font size. So, this should be an accurate conversion for percentages: px % 16 = 100 14 = 87.5 13 =...
4
6557
by: David Zha0 | last post by:
Hi, "when we call a virtual method, the runtime will check the instance who called the method and then choose the suitable override method, this may causes the performance drop down", is this...
5
1446
by: Ben | last post by:
Hi, i defined a function in the base class 'ford' and the same function (with different output) in subclass "peugeot". I first put 'Overridable function' in the base class and 'Overrides...
5
2213
by: Tony Johansson | last post by:
Hello! Here I have an Interface called ITest and a class called MyClass which derive this intrface. As you can see I don't implement this method myTest in class MyClass because i use the...
4
1751
by: Tony | last post by:
Hello! Below I have a complete working program.with some simple classes one of these is a generic class. The question is about this method GetCows() {...} which is a member in the generic...
6
1560
by: Tony | last post by:
Hello! Below I have a complete working program.with some simple classes one of these is a generic class. Now If I want to implement functionallity so I can compare animal with each other or...
0
7194
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7070
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
7267
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,...
1
6976
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7449
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4993
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4666
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3148
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
729
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.