Search code examples
c#code-readability

Long c# file breakdown


I have a Window Form App project. At the moment all of my code is in Form1.cs file which is the default file. Now I have about 1300 lines of code in this single file. I want to break down this one file code into several files to increase readability and easy handling. Is there an way to do that.

Thanks


Solution

  • If you do not want to do anything drastic you can split your class with the partial keyword and place each piece in its own file.

    public partial class Form1 { // file1.cs }
    public partial class Form1 { // file2.cs }
    

    See http://msdn.microsoft.com/en-us/library/wa80x488(v=vs.80).aspx