473,508 Members | 2,330 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do you sort/group your C# code?

Hi all,

I'm wondering if you how you organize as (in sorting / order) your C# class code:

Do you sort/ group by member type: fields, methods, properties etc.?
If yes: what ordering scheme do yo use?

Do you group members by visibility - and how does that relate to grouping by type?

Where do you insert (nested) types such as enums and delegates in classes
and namespaces? any order?, top, bottom grouped by type?

The reason I ask is that I'm implementing a sorting / rearrange algorithm
in ModelMaker Code Explorer for C# classes and namespaces.

Check for details on ModelMaker Code Explorer:
http://www.modelmakertools.com
Thanks for your feedback,

Gerrit Beuze
ModelMaker Tools
Nov 16 '05 #1
12 4212

"Gerrit Beuze" <gerrit[at]modelmaker[dot]demon[dot]nl> wrote in message
news:uO*************@tk2msftngp13.phx.gbl...
Hi all,

I'm wondering if you how you organize as (in sorting / order) your C# class code:
Do you sort/ group by member type: fields, methods, properties etc.?
If yes: what ordering scheme do yo use?

Do you group members by visibility - and how does that relate to grouping by type?
Where do you insert (nested) types such as enums and delegates in classes
and namespaces? any order?, top, bottom grouped by type?
Well the following is how I arrange my files, but please don't feel I'm
suggesting this is the One True Order.

1. Public nested types
2. Constructors (public, protected or private)
3. Public properties
4. Public methods
5. Protected methods
6. Private methods
7. Private nested types
8. Private member fields

My rationale for this is that you read the code like you read a story; you
dig deeper as you read further. Thus public nested types go first because
they are usually used throughout the type. Constructors come next, of all
accessibility, since they give the first indication of the use of the class
(protected? static methods only? standard? etc...). Next comes the rest of
the public and protected stuff (protected really forms part of the client
interface, so it goes with public). You could stop reading there, or dig
deeper into the actual implementation, which is of course last.

1 and 8 usually go in regions. The others are regioned by common
functionality, rather than accessibility.

Hope that's of interest,

Stu

The reason I ask is that I'm implementing a sorting / rearrange algorithm
in ModelMaker Code Explorer for C# classes and namespaces.

Check for details on ModelMaker Code Explorer:
http://www.modelmakertools.com
Thanks for your feedback,

Gerrit Beuze
ModelMaker Tools

Nov 16 '05 #2
1. Nested classes / enums.
2. Static fields.
3. Static methods.
4. Lifecycle (ie. constructor, finalize)
5. Public/Protected Instance fields.
6. Public/Protected Instance properties.
7. Public/Protected Instance methods.
8. Private Instance fields.
9. Private Instance properties.
10. Private Instance methods.

Also I enclose each of these in #region ... #endregion and collapse them all
down before checking a project in.

Chris.

"Gerrit Beuze" wrote:
Hi all,

I'm wondering if you how you organize as (in sorting / order) your C# class code:

Do you sort/ group by member type: fields, methods, properties etc.?
If yes: what ordering scheme do yo use?

Do you group members by visibility - and how does that relate to grouping by type?

Where do you insert (nested) types such as enums and delegates in classes
and namespaces? any order?, top, bottom grouped by type?

The reason I ask is that I'm implementing a sorting / rearrange algorithm
in ModelMaker Code Explorer for C# classes and namespaces.

Check for details on ModelMaker Code Explorer:
http://www.modelmakertools.com
Thanks for your feedback,

Gerrit Beuze
ModelMaker Tools

Nov 16 '05 #3


Take a look at this article

http://www.c-sharpcorner.com/Code/20...ingRegions.asp
"Chris Ballard" wrote:
1. Nested classes / enums.
2. Static fields.
3. Static methods.
4. Lifecycle (ie. constructor, finalize)
5. Public/Protected Instance fields.
6. Public/Protected Instance properties.
7. Public/Protected Instance methods.
8. Private Instance fields.
9. Private Instance properties.
10. Private Instance methods.

Also I enclose each of these in #region ... #endregion and collapse them all
down before checking a project in.

Chris.

"Gerrit Beuze" wrote:
Hi all,

I'm wondering if you how you organize as (in sorting / order) your C# class code:

Do you sort/ group by member type: fields, methods, properties etc.?
If yes: what ordering scheme do yo use?

Do you group members by visibility - and how does that relate to grouping by type?

Where do you insert (nested) types such as enums and delegates in classes
and namespaces? any order?, top, bottom grouped by type?

The reason I ask is that I'm implementing a sorting / rearrange algorithm
in ModelMaker Code Explorer for C# classes and namespaces.

Check for details on ModelMaker Code Explorer:
http://www.modelmakertools.com
Thanks for your feedback,

Gerrit Beuze
ModelMaker Tools

Nov 16 '05 #4
Along these same lines, what do you all use for C# code formatting (code
beautifiers)? Does anyone have any suggestions?

Thank you for your consideration.
"James Divine" <Ja*********@discussions.microsoft.com> wrote in message
news:4C**********************************@microsof t.com...


Take a look at this article

http://www.c-sharpcorner.com/Code/20...ingRegions.asp
"Chris Ballard" wrote:
1. Nested classes / enums.
2. Static fields.
3. Static methods.
4. Lifecycle (ie. constructor, finalize)
5. Public/Protected Instance fields.
6. Public/Protected Instance properties.
7. Public/Protected Instance methods.
8. Private Instance fields.
9. Private Instance properties.
10. Private Instance methods.

Also I enclose each of these in #region ... #endregion and collapse them
all
down before checking a project in.

Chris.

"Gerrit Beuze" wrote:
> Hi all,
>
> I'm wondering if you how you organize as (in sorting / order) your C#
> class code:
>
> Do you sort/ group by member type: fields, methods, properties etc.?
> If yes: what ordering scheme do yo use?
>
> Do you group members by visibility - and how does that relate to
> grouping by type?
>
> Where do you insert (nested) types such as enums and delegates in
> classes
> and namespaces? any order?, top, bottom grouped by type?
>
> The reason I ask is that I'm implementing a sorting / rearrange
> algorithm
> in ModelMaker Code Explorer for C# classes and namespaces.
>
> Check for details on ModelMaker Code Explorer:
> http://www.modelmakertools.com
>
>
> Thanks for your feedback,
>
> Gerrit Beuze
> ModelMaker Tools
>
>
>

Nov 16 '05 #5
Gerrit,

I think that an important point to make here is that not all
enumerations are nested (nor should they be, generally, there are few
enumerations that really belong as a nested type). The same thing goes with
delegates, although I think that there is more of a case for nested
delegates than there is for nested enumerations.

Also, with the advent of partial classes, I actually will place my
nested code in another file.

For fields, if there is a property that exposes them, then I try and
place the field close to the property. Other than that, I don't take the
time to arrange the properties and methods in any particular order. I
usually have my code factored out to a degree where I do not have insanely
huge class files (and if I did, they are just going to be listed all
alphabetically in the project view, or reflector anyways).
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Gerrit Beuze" <gerrit[at]modelmaker[dot]demon[dot]nl> wrote in message
news:uO*************@tk2msftngp13.phx.gbl...
Hi all,

I'm wondering if you how you organize as (in sorting / order) your C#
class code:

Do you sort/ group by member type: fields, methods, properties etc.?
If yes: what ordering scheme do yo use?

Do you group members by visibility - and how does that relate to grouping
by type?

Where do you insert (nested) types such as enums and delegates in classes
and namespaces? any order?, top, bottom grouped by type?

The reason I ask is that I'm implementing a sorting / rearrange algorithm
in ModelMaker Code Explorer for C# classes and namespaces.

Check for details on ModelMaker Code Explorer:
http://www.modelmakertools.com
Thanks for your feedback,

Gerrit Beuze
ModelMaker Tools

Nov 16 '05 #6
Bill,

With VS.NET 2005, I use just the IDE. There is a huge number of options
now regarding formatting of code. There is little need for me to beautify
it, because the IDE goes to great lengths to get it right the first time.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Bill O" <billo@_imt_net> wrote in message
news:OW*************@TK2MSFTNGP10.phx.gbl...
Along these same lines, what do you all use for C# code formatting (code
beautifiers)? Does anyone have any suggestions?

Thank you for your consideration.
"James Divine" <Ja*********@discussions.microsoft.com> wrote in message
news:4C**********************************@microsof t.com...


Take a look at this article

http://www.c-sharpcorner.com/Code/20...ingRegions.asp
"Chris Ballard" wrote:
1. Nested classes / enums.
2. Static fields.
3. Static methods.
4. Lifecycle (ie. constructor, finalize)
5. Public/Protected Instance fields.
6. Public/Protected Instance properties.
7. Public/Protected Instance methods.
8. Private Instance fields.
9. Private Instance properties.
10. Private Instance methods.

Also I enclose each of these in #region ... #endregion and collapse them
all
down before checking a project in.

Chris.

"Gerrit Beuze" wrote:

> Hi all,
>
> I'm wondering if you how you organize as (in sorting / order) your C#
> class code:
>
> Do you sort/ group by member type: fields, methods, properties etc.?
> If yes: what ordering scheme do yo use?
>
> Do you group members by visibility - and how does that relate to
> grouping by type?
>
> Where do you insert (nested) types such as enums and delegates in
> classes
> and namespaces? any order?, top, bottom grouped by type?
>
> The reason I ask is that I'm implementing a sorting / rearrange
> algorithm
> in ModelMaker Code Explorer for C# classes and namespaces.
>
> Check for details on ModelMaker Code Explorer:
> http://www.modelmakertools.com
>
>
> Thanks for your feedback,
>
> Gerrit Beuze
> ModelMaker Tools
>
>
>


Nov 16 '05 #7
If you're going to provide a generally usable tool you will need to allow
the developer to define what order they want this stuff in. It's a personal
or team decision, very individual, and there is no one "right" way and
probably not any one "most commonly used" way.

I do group methods alphabetically within a particular visibility -- public,
then protected, then private. Not everyone will do that, but I'm sure a lot
of folks do.

--Bob

"Gerrit Beuze" <gerrit[at]modelmaker[dot]demon[dot]nl> wrote in message
news:uO*************@tk2msftngp13.phx.gbl...
Hi all,

I'm wondering if you how you organize as (in sorting / order) your C#
class code:

Do you sort/ group by member type: fields, methods, properties etc.?
If yes: what ordering scheme do yo use?

Do you group members by visibility - and how does that relate to grouping
by type?

Where do you insert (nested) types such as enums and delegates in classes
and namespaces? any order?, top, bottom grouped by type?

The reason I ask is that I'm implementing a sorting / rearrange algorithm
in ModelMaker Code Explorer for C# classes and namespaces.

Check for details on ModelMaker Code Explorer:
http://www.modelmakertools.com
Thanks for your feedback,

Gerrit Beuze
ModelMaker Tools

Nov 16 '05 #8
I would say there is probably one "commonly used" process, which is putting
variables/constants (even within a protection-level grouping) - at the top
of a class/procedure. Aside from that, everything is fair game!!
"Bob Grommes" <bo*@bobgrommes.com> wrote in message
news:eR**************@TK2MSFTNGP12.phx.gbl...
If you're going to provide a generally usable tool you will need to allow
the developer to define what order they want this stuff in. It's a
personal or team decision, very individual, and there is no one "right"
way and probably not any one "most commonly used" way.

I do group methods alphabetically within a particular visibility --
public, then protected, then private. Not everyone will do that, but I'm
sure a lot of folks do.

--Bob

"Gerrit Beuze" <gerrit[at]modelmaker[dot]demon[dot]nl> wrote in message
news:uO*************@tk2msftngp13.phx.gbl...
Hi all,

I'm wondering if you how you organize as (in sorting / order) your C#
class code:

Do you sort/ group by member type: fields, methods, properties etc.?
If yes: what ordering scheme do yo use?

Do you group members by visibility - and how does that relate to grouping
by type?

Where do you insert (nested) types such as enums and delegates in classes
and namespaces? any order?, top, bottom grouped by type?

The reason I ask is that I'm implementing a sorting / rearrange algorithm
in ModelMaker Code Explorer for C# classes and namespaces.

Check for details on ModelMaker Code Explorer:
http://www.modelmakertools.com
Thanks for your feedback,

Gerrit Beuze
ModelMaker Tools


Nov 16 '05 #9

"Drebin" <th*******@hotmail.com> wrote in message
news:fu*****************@newssvr17.news.prodigy.co m...
I would say there is probably one "commonly used" process, which is putting
variables/constants (even within a protection-level grouping) - at the top
of a class/procedure. Aside from that, everything is fair game!!


You would be wrong.

It isn't uncommon, by any means, to group by overall functionality. For a
minor eaxmple, I happen to often declare fields with wrapping properties. I
doubt I'm alone in this regard.

Also, since I group methods and properties by common functionality(that is,
MethodA and MethodA's helpers and overloads) into one group, fields unique
to those method would be contained within that group as well.

In procedures I declare variables at visibility level much of the time(that
is at teh top of the *block* they are used in, not nessecerily the procedure
itself), but I am certainly not shy about declaring one in-code if it is in
use for only a few lines. And I *know* I'm not alone on that.
Nov 16 '05 #10
Wow. I wouldn't have thought I deserved that. Nice.

"Daniel O'Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> wrote in
message news:uZ*************@TK2MSFTNGP12.phx.gbl...

"Drebin" <th*******@hotmail.com> wrote in message
news:fu*****************@newssvr17.news.prodigy.co m...
I would say there is probably one "commonly used" process, which is
putting variables/constants (even within a protection-level grouping) - at
the top of a class/procedure. Aside from that, everything is fair game!!


You would be wrong.

Nov 16 '05 #11
Drebin,

I wouldn't have been as forceful, but I have to agree with much of what
Daniel said (as it is the way I find myself organizing my code).
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Drebin" <th*******@hotmail.com> wrote in message
news:xF****************@newssvr19.news.prodigy.com ...
Wow. I wouldn't have thought I deserved that. Nice.

"Daniel O'Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> wrote in
message news:uZ*************@TK2MSFTNGP12.phx.gbl...

"Drebin" <th*******@hotmail.com> wrote in message
news:fu*****************@newssvr17.news.prodigy.co m...
I would say there is probably one "commonly used" process, which is
putting variables/constants (even within a protection-level grouping) -
at the top of a class/procedure. Aside from that, everything is fair
game!!


You would be wrong.


Nov 16 '05 #12

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:u%****************@TK2MSFTNGP15.phx.gbl...
Drebin,

I wouldn't have been as forceful, but I have to agree with much of what
Daniel said (as it is the way I find myself organizing my code).


Hrmm, I didn't think I *was* being forceful. Certainly wasn't trying to be.
Is it that people expect me to be harsh(there is plenty of history to
support that) or does my writing simply come off that way?
Nov 16 '05 #13

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

Similar topics

18
6178
by: googleboy | last post by:
I didn't think this would be as difficult as it now seems to me. I am reading in a csv file that documents a bunch of different info on about 200 books, such as title, author, publisher, isbn,...
2
2991
by: Wiseguy | last post by:
OK. I need to sort a list and I have the following code @L=(35,10,0,27,100,-4); sub numeric { $A <=> $b; } @L=sort numeric @L; The only reference I have is an ancient Oreilly book on Perl 4....
11
3875
by: James P. | last post by:
Hello, I have a report with the Priority field is used as sort order and grouping. The problem is the data in this Priority field if sorted in ascending order is: High, Low, and Medium. How...
2
1575
by: Danny | last post by:
HI, I am trying to do a group by such as this: "select code, colors from productdb group by code, colors" I need to sort on the key field, but cannot throw in the 'ordre by key', because i...
34
7273
by: Mark Kamoski | last post by:
Hi-- Please help. I need a code sample for bubble sort. Thank you. --Mark
3
2954
by: Bob Dankert | last post by:
Is there any way to maintain the sort order of a sort on a 2D array? For example: I have the array: 1,a 2,a 3,f 4,a 5,s 6,a 7,z 8,b and sort it by the second column, and I...
21
3168
by: yeti349 | last post by:
Hi, I'm using the following code to retrieve data from an xml file and populate a javascript array. The data is then displayed in html table form. I would like to then be able to sort by each...
2
7748
by: adrian.chandler | last post by:
Hi all, I have been using letter and symbol codes such as GNU< GNU\ GNU} GNUˆ in an Access table. I was surprised to see that when the table was sorted on this field, the order is: GNUˆ...
1
3234
by: Martin.Molch | last post by:
Hello, DB2 seems to do a SORT before every GROUP BY action. At least if I look at the query plan (using Visual Explain in the Command Center) of -- connected to the sample db SELECT WORKDEPT,...
0
1389
by: jatuphum | last post by:
Hi all, I have xml like these below. <Listing> <Avail> <Field1>aaa</Field1> <Field2>800</Field2> <Field3>900</Field3> <SortValue>20.00</SortValue>
0
7233
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
7342
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
7067
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
7505
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...
0
5650
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5060
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
4729
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
3201
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
774
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.