
Partial classes span multiple files. How can you use the partial modifier on a C# class declaration? With partial, you can physically separate a class into multiple files. This is often done by code generators.
This C# article shows how to use the partial class modifier. Partial classes are spread out among several files.

With normal C# classes, you cannot declare a class in two separate files in the same project. However, if you use the partial modifier, you can do exactly this. This is most useful if one file is commonly edited and the other is machine-generated or rarely edited.
Program that uses partial class [C#]
class Program
{
static void Main()
{
A.A1();
A.A2();
}
}
Contents of file A1.cs [C#]
using System;
partial class A
{
public static void A1()
{
Console.WriteLine("A1");
}
}
Contents of file A2.cs [C#]
using System;
partial class A
{
public static void A2()
{
Console.WriteLine("A2");
}
}
Output
A1
A2Partial is required here. If you remove the partial modifier, you will get an error containing this text: [The namespace '<global namespace>' already contains a definition for 'A']. To fix this, you can either use partial, or change one of the class names.

How does the C# compiler deal with partial classes? If you disassemble the above program, you will see that the files A1.cs and A2.cs are eliminated and the class A is present. Class A will contain the methods A1 and A2 in the same code block. Thus, partial classes are precisely equivalent to a single class with all the members.
Compiled result of A1.cs and A2.cs [C#]
internal class A
{
// Methods
public static void A1()
{
Console.WriteLine("A1");
}
public static void A2()
{
Console.WriteLine("A2");
}
}
Partial classes can simplify certain C# programming situations. They are often used in Visual Studio when creating Windows Forms programs; the machine-generated C# code is separate. They can also sometimes be used to separate commonly-edited code from rarely-edited code. This can reduce confusion and the possibility that code that isn't supposed to be edited is changed.
Class