Partial Class
Partial Class
Ø This concept is used to divide a class code into different parts.
Ø A partial class is declared using partial key word.
Ø When we declare a class as partial, the methods of the class or the class code can be written anywhere with in the same assembly.
See the following example:
First create the console Application using the following code.
namespace PartialClass
{
partial class Employee
{
int empid, age;
string ename, address;
public void Getempdata()
{
Console.WriteLine("Enter empid,ename,age,address:");
empid = Convert.ToInt32(Console.ReadLine());
ename = Console.ReadLine();
age = Convert.ToInt32(Console.ReadLine());
address = Console.ReadLine();
}
}
}
Add a new file to the solution.Go to new class file ,write the following code.
namespace PartialClass
{
partial class Employee
{
public void DisplayEmpdata()
{
Console.WriteLine("empid is:" + empid);
Console.WriteLine("empname is:" + ename);
Console.WriteLine("emp age is:" + age);
Console.WriteLine("emp address is:" + address);
}
}
class Partial
{
static void Main ()
{
Employee obj=new Employee();
obj.Getempdata();
obj.DisplayEmpdata();
Console.ReadLine();
}
}
}
Run The Appilication and Check.
BY
VIJAY

