in .NET Framework

Best Coding Practices – TIP 3

The use of partial classes can help improve coding for the following reasons:

  • As you can split code into seperate physical files, its easier to seperate UI and Business Logic that may belong in a single class
  • Produces clean and organised code
  • No performance hit… The compiler groups all partial classes into one entity during compilation

Sample Code

MyFile1.cs

public partial class MyPartialClass

{

int foo = 0;

}

MyFile2.cs

public partial class MyPartialClass

{

public String ShowMessage()

{

return foo.ToString();

}

}

REMEMBER: Keep partial classes in the same namespace to avoid confusion!