The simple example of the partial class in c#

c# allow a new feature called partial classes. With partial classes, we can spread the definition of a class over multiple files.
The partial class definitions can be split up across multiple physical files. At the time of compiling your application, compiler treats it as a single class. Writing partial class is useful When working on large projects, spreading a class over separate files allows multiple programmers to work on it simultaneously.

Below is the example of a partial class.
 
Writing code for class Student in a one file:

  public class Student
    {
        private string StudentName;
        public void Addnew()
        {
            // do something
        }
 
        public void AddAge(string name)
        {
            // do something
        }
    }

Split the Class Student across multiple files:

public partial class Student
    {
        private string StudentName;
        public void Addnew()
        {
            // do something
        }
    }

 

    public partial class Student
    {
        public void AddAge(string name)
        {
            // do something
        }
    }

 
We use partial classes to split up our larger classes. That way it’s easier to check out a part of the code.