In C# we have the concept of partial classes.
Partial class is simply a splitting of class file. When the source code will be compiled all the partial class unites and forms up a single class.
This is introduce to
1. When multiple programmers are working on same class then they both declare their classes as partial class, and when the source code is compiled it will form single class.
2. In Asp.Net we have webpage.aspx and webpage.aspx.cs file. Both these classes are partial class and will unite to one single class.
/*-----------------------------------------------------------------------------------------*/
// Start Code by Developer 1 in his machine//
public partial class Employee
{
private int employeeID;
public int GetEmployeeID()
{
return
employeeID;
}
public void setEmployeeID(int
employeeID)
{
this.employeeID
= employeeID;
}
}
// End of Code by Developer 1 //
// Start Code by Developer 2 in his machine //
// Start Code by Developer 2 in his machine //
public partial class Employee
{
private string employeeName;
public string GetEmployeeName()
{
return
employeeName;
}
public void SetEmployeeName(string
employeeName)
{
this.employeeName
= employeeName;
}
}
// End of Code by Developer 2 //
// Start Code by Senior Developer //
// Start Code by Senior Developer //
class Program
{
static void Main(string[]
args)
{
Employee emp = new
Employee();
emp.setEmployeeID(1); // By Developer 1
emp.SetEmployeeName("TestName"); // By Developer 2
Console.WriteLine("employeeID in partial class is " +
emp.GetEmployeeID());
Console.WriteLine("employeeName in partial class is " +
emp.GetEmployeeName());
Console.Read();
}
}
// End Code by Senior Developer
/*-----------------------------------------------------------------------------------------*/
/*-----------------------------------------------------------------------------------------*/
No comments:
Post a Comment