In this blog, I’m explaining about the partial classes in C#.

A partial class allow a single class to be divided into two separate physical file.

During compile time, these files get compiled into a single class.

Example
namespace PartialClassProgram
{
  partial class PartialClass
{
  public void add(int a, int b)
 {
     System.Console.WriteLine("Result=" + a + b);
 }
}
partial class PartialClass
{
   public void add(string a, string b)
  {
     System.Console.WriteLine("Result=" + a + b);
  }
}
class Program
{
static void Main(string[] args)
  {
  string s = "String1";
string s1 = " String2";
PartialClass objpartial = new PartialClass();
  objpartial.add(s, s1);
objpartial.add(1, 2);
Console.ReadLine();
  }
 }
 }

Leave Comment