Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

c#
basics
oop

Partial classes in C#

Educative Answers Team

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();
    }
}

RELATED TAGS

c#
basics
oop
Copyright ©2022 Educative, Inc. All rights reserved
RELATED COURSES

View all Courses

Keep Exploring