Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Best Practice Organising Classes in Class files 2

Status
Not open for further replies.

golcarlad

Programmer
Nov 23, 2004
232
GB
Whats the best practice to organise your code - e.g. if you have an abstract class and its derived classes - do you seperate each of your classes into their own class file (foo.cs) or do you keep them all in the same physical cs file??

I would have thought it could get cumbersome to have to naviagate to lots of different cs files in your project just to find the class you are after??

Your thoughts and ideas are welcomed.
 
each class (abstract or otherwise) gets its own source file, named <class>.cs.

if the class is declared partial, usually because one part is machine generated, the first redefinition source file is called <class>Ex.cs.

it's really not that cumbersome to do this, since shortcut-G is "Go To Definition" which allows you to navigate the classes pretty painlessly.

the only occasion i'd put two classes in the same source file is if the second one is entirely contained by the first, since fxcop doesn't allow you actually to nest classes.

now, if only the class explorer could deal with the number of classes in my project without choking i'd be all set.


mr s. <;)

 
I always break each class into its own file. makes searching for a class a bit easier/cleaner.

I also put all enumerations into one file Enums.cs
this stops people from creating the same enumeration multiple times (it's dumb but it happens)

 
one question, a delegate declaration is one line of code but is pretty much the same as a class declaration.

does it get its own source file?

mr s. <;)

 
This one I'm guilty of. I tend to create delegates right below the class I'm using them in. It gets messy and all delegates should really be created in a single file or in several classified files so that they are organized.

 
Interesting guys - why did this not come naturally to me???
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top