Partial classes in C#

A partial class is one of the exclusive features of C#. With this feature, you can divide the functionality of one particular class into multiple different classes with the same name.

Use partial as a keyword to define partial classes.

svg viewer

Code

In the code below, we have two different partial classes for a Person class. In the Person1 class, we have a parameterized constructor for its Name and Age. In Person2 class, we have a Print() function that prints Name and Age. When we execute this program, the compiler compiles these two partial classes into one single class.

main.cs
Person1.cs
Person2.cs
class PartialClassTest
{
static void Main()
{
Person obj = new Person("Jane", 28);
obj.Print();
}
}

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved