By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,730 Members | 1,480 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,730 IT Pros & Developers. It's quick & easy.

Suggestions for standard regions

P: n/a
Just starting on C# and would like to know what suggestions
there are for the order in which declarations, event
handlers, properties, private code, nested classes, etc,
etc appear in your files. What impact do access modifiers
have on the order? Also, does anyone use standardised
region names?

Nov 16 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Hi...

You may want to check for C# Coding Standard via Google or AllTheWeb.com.
Many of the published standards address this question.

John Puopolo

"Simon" <an*******@discussions.microsoft.com> wrote in message
news:12****************************@phx.gbl...
Just starting on C# and would like to know what suggestions
there are for the order in which declarations, event
handlers, properties, private code, nested classes, etc,
etc appear in your files. What impact do access modifiers
have on the order? Also, does anyone use standardised
region names?

Nov 16 '05 #2

P: n/a
Yes, I have already found some good references from
Phillips, IDesign (Juval), Lance Hunt and MSDN. However,
none of them, unless I've missed it, tackle the issue of
what order to do things in. Of course, I can make my own
up, but I would have thought this would have been dealt
with. Perhaps it's not as interesting as brace placement or
the use of tabs which both seem to be hot topics of debate ;)

-----Original Message-----
Hi...

You may want to check for C# Coding Standard via Google or AllTheWeb.com.Many of the published standards address this question.

John Puopolo

"Simon" <an*******@discussions.microsoft.com> wrote in message
news:12****************************@phx.gbl...
Just starting on C# and would like to know what suggestions
there are for the order in which declarations, event
handlers, properties, private code, nested classes, etc,
etc appear in your files. What impact do access modifiers
have on the order? Also, does anyone use standardised
region names?

.

Nov 16 '05 #3

P: n/a
"Simon" <an*******@discussions.microsoft.com> wrote in message
news:12****************************@phx.gbl...
Just starting on C# and would like to know what suggestions
there are for the order in which declarations, event
handlers, properties, private code, nested classes, etc,
etc appear in your files. What impact do access modifiers
have on the order? Also, does anyone use standardised
region names?


Over the years I've tried diffrent approaches and tried to have well defined
rules for all my classes.
Rules like starting withall public methods and public events, then the
protected and finally the proivate parts.

However, I've given up all such efforts.

I have found that no rules is best practice. But what I do try to do is
imagining that I am a maintainer who have never seen my code before. From
that I try to place the most important methods in the order they are
typically being called. If a public method calls three private methods, I
try to keep the private once close to the public caller.

Simple and obvious methods I put at the bottom of the source file.

Oh, and I tend to make sure that an class member variables are at the top of
the class.

- Michael S
Nov 16 '05 #4

P: n/a
Here's the order of regions that I use:
fields
events
properties
constructors
instance methods
static methods

This is not a complete list, and I agree with Michael S mostly. There
is no way I could come up with rules for this and stick with them. The
above is what I _tend_ to do, but there are times when I create more
specialized regions to enhance maintainability. I also alphabatize
members within regions.

Best regards,
Jeffrey Palermo
Blog: http://www.jeffreypalermo.com

Nov 16 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.