Partial Class

Partial class is a special feature of C#. It provides a special ability to split single class into multiple files and all these files are combined into a single class file when the application is compiled. A partial class is created by using a partial keyword. This keyword is also useful to split the functionality of methods, interfaces, or structure into multiple files.

CODE

EG 1 . Spliting single Rectangle class into multiple partial classes.

partial class Rectangle {
    public static double length, width;
    public static double Area() {
        return length * width;
    }
}

partial class Rectangle {
    public static double height;
    public static double Volume() {
        return Area() * height;
    }
}

partial class Rectangle {
    public static double density;
    public static double Weight() {
        return Volume() * density;
    }
}

class Program {
    static void Main() {
        Rectangle.length = 5;
        Rectangle.width = 6;
        Rectangle.height = 7;
        Rectangle.density = 2.8;
        Console.WriteLine(Rectangle.Area());
        Console.WriteLine(Rectangle.Volume());
        Console.WriteLine(Rectangle.Weight());
    }
}