Background
In this article, we will learn about one of the most reusable object-oriented features of C#, Partial Classes. We will learn about Partial Classes from the basics because I have written this article focusing on students and beginners. Before proceeding further, please refer to my previous articles for a better understanding.
- Programming Methodologies
- Types of Classes in C#
- Polymorphism in C#
- Using Abstract Class in C#
- Types of Inheritance in C#
What is partial?
It is the type of class that allows dividing methods into multiple class source files and at compile time, these files are combined into one single class. A partial class allows the definition of methods into two different class source files and at execution time, these files are combined together.
Some key points about Partial Classes
- All the parts of a partial class must be prefixed with the partial keyword.
- If you seal any specific part of a partial class, then the entire class is sealed; the same as in an abstract class.
- Inheritance cannot be applied to partial classes.
To demonstrate more about partial classes, let us create a simple console application by creating two partial classes into two different class source files, as in:
- Open Visual Studio from "Start" -> "All programs" -> "Microsoft Visual Studio".
- Then, go to "File" -> "New" -> "Project..." then select "Visual C#" -> "Windows" -> "Console application".
- Then, specify the name such as Partial class or whatever name you wish and the location of the project and click on the "OK" button. The new project is created.
- Right-click on Solution Explorer and add two class files. After adding them, the Solution Explorer will look like below.

- partial class car
- {
- public string Method1()
- {
- return "This is method 1 of class car";
- }
- }
- partial class car
- {
- public string Method2()
- {
- return "This is method 2 of the class car";
- }
- }
- public class Program
- {
- static void Main(string[] args)
- {
- car obj = new car();
- Console.WriteLine( obj.Method1());
- Console.WriteLine(obj.Method2());
- Console.ReadLine();
- }
- }
Download the Zip file from the attachment for the full source code of the application.
Summary
In the preceding article, I have briefly explained the use of partial classes to make them understandable to beginners and newcomers. If you have any suggestion regarding this article, then please comment below.

Join the conversation! Your thoughts help the community grow.