Reputation:
I have a class that is getting to be large. How do i define it so methods can span across different .cs files?
Upvotes: 2
Views: 235
Reputation: 31174
You can use a partial class for this.
http://msdn.microsoft.com/en-us/library/wa80x488(VS.80).aspx
Employee_1.cs
public partial class Employee
{
public void DoWork()
{
}
}
Employee_2.cs
public partial class Employee
{
public void GoToLunch()
{
}
}
Upvotes: 7
Reputation: 46435
It might be nice having multiple smaller files, but it will be more of a pain to find the correct code when its split across two files.
Upvotes: 1
Reputation: 14868
Use the partial
keyword.
Foo.cs
public partial class Foo
{
.....
}
xFoo.cs
public partial class Foo
{
......
}
However, if your class is getting large, it's probably a bit of a code smell and time to think about refactoring.
Upvotes: 3
Reputation: 545638
You can declare your class as partial
. This allows you to split it over multiple files.
// File 1:
partial class Test {
public void Method1() { … }
}
// File 2
partial class Test {
public void Method2() { … }
}
Upvotes: 10