Partial class
Partial class, interface and structure was introduced in C# 2.0. Now it is possible to split the definition of an class, interface and structure over more than one source files. Moreover the other parts of the class, struct, or interface should be defined in the same namespace or assembly. All the parts must have the partial keyword and same access modifier like as public, private, and so on.
Example program
- using System;
- namespace CAPartil
- {
- partial class ClsEmployee
- {
- int Empid, Eage;
- public void GetEmpDetails()
- {
- Console.WriteLine("Enter id");
- Empid = Convert.ToInt32(Console.ReadLine());
- Console.WriteLine("Enter Age");
- Eage = Convert.ToInt32(Console.ReadLine());
- }
- }
- class clsmain
- {
- public static void Main()
- {
- ClsEmployee obj = new ClsEmployee();
- obj.GetEmpDetails();
- obj.DisplayEmpDetails();
- Console.ReadLine();
- }
- }
- }
- using System;
- namespace CAPartil
- {
- partial class ClsEmployee
- {
- //int Empid, Eage;
- public void DisplayEmpDetails()
- {
- Console.WriteLine("Emp id" + this.Empid);
- Console.WriteLine("Emp Age" + this.Eage);
- }
- }
- }