In C#, is there a way to separate code that is in the same class into separate files?
c#, class, object, oop, visual-studio
Solution
Yes. Just use the `partial` keyword for each "part" of the class in the class' files.
// example class A in file: A1.cs
public partial class A { }
// example class A in file: A2.cs
public partial class A { }
More information can be found at MSDN and a thousand other sites and blogs.
Problem
I recently inherited some code that is several thousand lines long and extremely disorganized. I'm trying to re-factor it so that code is at least easier to find, but since it was built in visual studio, everything is contained within a single "form" class, and the way it's written makes it difficult to separate code without breaking something. Is there a way that I could have the code live in a different file, but still keep it in the same class?