Home > DeveloperSection > Blogs > Partial Classes in C#

Partial Classes in C#


.NET .NET 
Ratings:
0 Comment(s)
 738  View(s)
Rate this:

Partial Classes in C#

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();

  }

 }

 }


Don't want to miss updates? Please click the below button!

Follow MindStick