Best Coding Practices – TIP 3

Posted by Tim on February 20, 2009 in .NET Framework, C# |

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!

Tags: ,

Leave a Reply

Copyright © 2008-2012 Codelab Blog All rights reserved.
Desk Mess Mirrored version 1.9.1 theme from BuyNowShop.com.