Let's jump right into a brief look at partial classes in VS.Net 2005 Beta 2. First, I created a new Windows Console project.

I then added a new class file named PartialClassFile1.cs.

I then renamed the class PartialClassFile and added the partial keyword modifier to the class. I then added a publicly accessible static method that returned the string “From PFC1.”
|
using System; using System.Collections.Generic; using System.Text;
namespace PartialClassDemo { partial class PartialClassFile { public string MethodFromPCF1() { return "From PFC2"; } } } |
Next, I then added a new class file named PartialClassFile2.cs. I then renamed the class PartialClassFile and added the partial keyword modifier to the class as I had done with the previous class. I then added a publicly accessible method that returned the string “From PFC2.”
|
using System; using System.Collections.Generic; using System.Text;
namespace PartialClassDemo { partial class PartialClassFile { public static string MethodFromPCF1() { return "From PFC1"; } } } |
Then, I opened and modified the Program.cs file, which is created in VS.Net 2005 Beta 2 as part of a Windows Console app, to look like the following:
|
using System; using System.Collections.Generic; using System.Text;
namespace PartialClassDemo { class Program { static void Main(string[] args) { //get return from the static method contained in //the PartialClassFile1.cs file Console.WriteLine(PartialClassFile.MethodFromPCF1());
//make an instance of partial class to //and then invoke the method contained in //the PartialClassFile2.cs file PartialClassFile pcf = new PartialClassFile(); Console.WriteLine(pcf.MethodFromPCF2()); } } } |
Finally, I built and ran the solution and here is the resulting console:

According to the Partial Class Definitions (C# Programmer's Reference):
It is possible to split the definition of a class (or a struct, or an interface) over two or more source files. Each source file contains a section of the class definition, and all parts are combined when the application is compiled.
Out of curiosity, I opened the PartialClassDemo assembly, the PartialClassDemo.exe file, with IL Disassembler tool. Note that the MethodFromPCF1 and MethodFromPCF2 methods are compiled into the PartialClassDemo.PartialClassFile object from two different partial classes.

In conclusion, partial classes provide a way for several programmers to be concurrently developing on the same class, easier debugging as the code is separated into different files, and a cleaner encapsulation of code.