Azurewrath

Hi,

Is it better to write properties before methods in an interface Is there a optimal or preferred order for this and classes Like:

class def

{

properties

constructors

public property methods

methods

etc

}

Thanks,

aw



Re: Visual C# Language Order of properties, methods

Chris Rush

I basically use that design, except I would move my public property methods to be right below my privates.




Re: Visual C# Language Order of properties, methods

Azurewrath

To be honest I do it like you too. Ijust wrote the above because that is what the book does, sometimes.

Thanks,

aw





Re: Visual C# Language Order of properties, methods

Peter Ritchie

The only benefit you get from any organization of members is purely maintanence. I would suggest picking an organization and just being consistent. I prefer this order: data, private types, public interface (properties and methods), implementation.




Re: Visual C# Language Order of properties, methods

Matthew Watson

I personally put my privates after my publics (which I also used to do with my C++ classes).

My rationale for this is that when a user is looking at my source code to see how to use the class, they will look at the public part. If the publics are near the top, they won't have to scroll past a load of private implementation details to find them.

(I also use #regions to separate out the public/private bits, so if someone has got outlining turned on the order is less significant, of course.)




Re: Visual C# Language Order of properties, methods

Azurewrath

Thanks guys!

Btw Peter what did you mean with data (before private types)

So Matthew your order is like this :

public properties

private properties

public methods for private properties

constructors

methods

Also where do you guys put overriding standard methods, like ToString()

Thanks,

aw





Re: Visual C# Language Order of properties, methods

Peter Ritchie

data as in private fields, in the "pure" OO sense...




Re: Visual C# Language Order of properties, methods

Azurewrath

Thanks Peter. Are fields and properties the same thing Because it seems to a little confusing to me.

Thanks again,

aw





Re: Visual C# Language Order of properties, methods

Peter Ritchie

Azurewrath wrote:

Thanks Peter. Are fields and properties the same thing Because it seems to a little confusing to me.

Thanks again,

aw

No, fields are the data members (i.e. not methods, or properties.). Properties are technically implemented as methods.




Re: Visual C# Language Order of properties, methods

Azurewrath

Thanks Peter. So are they like this:

private int intCount = 5

If not, can you please give me an example

Thanks,

aw