Dec 29, 2019

PARTIAL CLASS IN C#

c# partial class, partial class, partial class examples, advantages of partial class
partial class in c#

PARTIAL CLASS

            The ability of splitting of a single class into multiple classes with the help of  the keyword ‘Partial’ known as partial class. This keyword is useful to split the functionality of method and interface.

SYNTAX

            [<Modifier>] partial class <Name>
{
  Class members;
}
[<Modifier>] partial class <Name>
{
  Class members;
}

EXAMPLE

            When we make two or more then partial class then at compilation time it compile as a class means combined all the class into one class and then compiled. Like this

Public partial class Test
{
  Public int a = 12;
  Public string name =”Meer”;
  Public void Info ( )
  {
   Console. WriteLine (“name ={0}   
    password ={1}”, a, name );
  }
}
Public partial class Test
{
  Public void login( )
  {
    Console. WriteLine (“you are now
   login into the partial class Test”);
  }
}

At a time of compilation it compile like

Public class Test
{
  Public int a = 12;
  Public string name =”Meer”;
  Public void Info ( )
  {
   Console. WriteLine (“name ={0}   
    password ={1}”, a, name );
  }
  Public void login( )
  {
    Console. WriteLine (“you are now
   login into the partial class Test”);
  }

}

ADVANTAGES OF PARTIAL CLASS

            There are some advantages when we declare a class as partial class.
            1.    Multiple developers can easily add their own program features such as method in the partial               class.
            2.    By making large and complex class into small class you can easily understand and maintain                 your application in efficient manner.

0 comments:

Post a Comment

Please do not enter any spam link in the comment box