Partial Class


A class can be defined over multiple source files. All of the source files are combined into one class when the application is compiled.

  • It is declared using the partial keyword.
  • All of the source files must use the partial keyword.
  • All the files must have the same access modifier, e.g. public, private, etc.
  • If any file is declared abstract, the whole class becomes abstract.
Example
namespace MyConsoleApp
{
    public partial class Student
    {
        public void AttendClass()
        { 
        }
    }

    public partial class Student
    {
        public void DoHomework()
        {
        }
    }
}

Back to Notes