Say,
No.Of Classes = 20
No.Of Methods in Class = 7
Is this okay to ..
1) create one .cs file including all 20 classes in one and each respective methods under them
2) create 20 .cs files and add those methods into that particular .cs file
Note: The look is from all sides.. like writing time, debugging time, performance, well organized... and so on...
So which one will do #1 or #2 or both has the same effect... ???
-
-
You should definitely NOT put them all in 1 file. Harder to manage, especially if multiple people should work on the same project. With .NET 2.0, you can even split a single class over multiple files (with partial classes), if it has become too big.
-
Put each class in one file. Usually even the file name should be the name of the class. It's easier to manage, when developing in a team. It's also easier to search for. If you, for example, would just look for a single class via explorer.
You should ask yourself: what happens if I have a 21th class or a 22th? Should I put them also in the same file? You will very soon understand that the single file approach doesn't scale. -
Thanks TommyCarlier and Littleguru.
I do follow the #2 sequence. I had seen some examples on #1 way. So i thought... Was I wrong? But not
. And thanks a lot for guiding... -
But if you have a small class that is used only by another class put them together in the same file!littleguru wrote:Put each class in one file.
-
Ion Todirel wrote:
But if you have a small class that is used only by another class put them together in the same file!
littleguru wrote: Put each class in one file.
I never do that. If the class is only used internally by the other class, i put it inside the class and make it private. Otherwise I put everything in an own file. What does it cost? Nothing. What's the benefits: You have one paradign, you follow - and that always - without exceptions. -
littleguru wrote:

Ion Todirel wrote:
But if you have a small class that is used only by another class put them together in the same file!
littleguru wrote: Put each class in one file.
I never do that. If the class is only used internally by the other class, i put it inside the class and make it private. Otherwise I put everything in an own file. What does it cost? Nothing. What's the benefits: You have one paradign, you follow - and that always - without exceptions.
I do the same thing. I even place structures, enumerations and other items within a seperate file. I also name the files according to the name of the class, enumeration, structure, etc. It really helps later when you need to manage the code or extend the features of code. -
So far as the compiler is concerned, it doesn't matter, however, conventional coding practices state that you should store each class in it's own file, inside a file named $ProjectDir\$Namespace\$Classname.cs. Each class should be self contained, potentially containing multiple #region ... #endregion statements which will help code collapse some of your sections of code.
Some companies/individuals prefer using the partial class syntax for large classes, however this is not typically of use to developers except where parts of the class are automatically generated (such as during Visual form development).
Thread Closed
This thread is kinda stale and has been closed but if you'd like to continue the conversation, please create a new thread in our Forums,
or Contact Us and let us know.