Wednesday, July 2, 2014

PARTIAL CLASSES

It is an approach of defining a class in more than one file i.e you can split a class into multiple files.

Parts.cs
Class parts
{
Method1()
Method2();
Method3()
Method4()
}

Part1.cs
Partial Class Parts
{
Method1()
Method2()
}

Part2.cs
Partial Class Parts
{
Method3()
Method4()
}

Partial classes provides the following benefit
Splitting up of huge volume of code into multiple files or separating related code into different files which make easy to manage.
Multiple programmers can write on the same class at a time.


Add a class as Part1.cs and write the following code

 Partial Class Parts
{
Public void Method1()
{
Console.writeline(“Method1”);
}
Public void Method2()
{
Console.writeline(“Method2”);
}
}

Part2.cs

 Partial Class Parts
{
Public void Method3()
{
Console.writeline(“Method3”);
}
Public void Method4()
{
Console.writeline(“Method4”);
}
}

Add a class as TestParts.cs and write the following code
Class TestParts
{
Static void Main()
{
Parts P=new Parts();
P.Method1();
P.Method2();
P.Method3();
P.Method4();
Console.ReadLine();
}

}

No comments:

Post a Comment

Thank you for visiting my blog

Kubernetes

Prerequisites We assume anyone who wants to understand Kubernetes should have an understating of how the Docker works, how the Docker images...