December 16, 2012

Partial Class


Partial Class

It will be situation in the project that two developers may work into same class simultaneously. But with only one physical file it is not possible to maintain all work done by both the programmers into the same file.
  • PARTIAL is a keyword used to define a class as partial class

  • By using partial classes it can be easily achieved.

  • Here class will be declared as partial so that the it is possible to split / divide the class , structures , interface into more than one source file.

  • At compile time these source files are compiled as a single source file.

  • So that multiple developers can work simultaneously with their own source file.

public partial class PartialClassDemo
{
    public int Addition(int no1 , int No2)
    {

        return no1 + no1;

    }
}

 
public partial class PartialClassDemo
{
    public int Subctraction(int no1, int No2)

    {

        return no1 - no1;

    }
}

In code behind file you can get both method after using PartialclassDemo class       PartialClassDemo oPar = new PartialClassDemo();
        int Sum = oPar.Addition(10, 20);

        int sub = oPar.Subctraction(30, 20);

 

No comments:

Post a Comment