Advantage of putting all classses into seperate .cs files RRS feed

  • Question

  • Reading through a few books some authors recommend that each class gets its own .cs file. Along with each interface, enum, delegate, and struct.

    As a group we use Resharper and Resharper even has a tool that will automatically seperate all of the mentioned types above into their own files with the push of a button.

    I believe this ia better for maintainability, but in order to convince my group to adhere to this what other, if any, benefits does this accomplish?


    Thursday, October 11, 2012 5:11 PM


  • I have 4 points here:

    1. Easy to read. When a new developer try to understand the project, he/she can clearly get the class and related interface, enum, delegate and struct. Do not start from a "mess".

    2. Easy to reuse. If the classse may be reused for other projects, you can simply get the code you want and do not need to pick things out from the "mess".

    3. Easy to document or define the purpose of the class.

    4. Good for source control. If a code file includes 3 classes and 2 developers want to change 2 of them, one has to wait for the other's work done. If the classes are seperated to seperate files, the developers can work without any confilict. 

    However, I don't think it is a must that put classess into seperate file. It is only a general best practice but not a rule. Having more than one classes in one file is fine if it makes sense.


    Alan Yao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, October 12, 2012 2:54 AM