Partial type in C#

What is partial type

We can use partial type modifier to split the type definition into more than one files.

The following code shows how to use the partial keyword.

File: Rectangle1.cs


partial class Rectangle{
   
}

File: Rectangle2.cs


partial class Rectangle{

}

Members cannot be duplicated across partial types.

Partial method

Partial type can have partial methods.


partial class Rectangle{
   partial void calculate();
/*from  w ww.j a v  a2s . co  m*/
}

partial class Rectangle{
   partial void calculate(){
      Console.WriteLine("doing the calculation");
   }
}




















Home »
  C# Tutorial »
    Custom Types »




C# Class
C# Struct
C# Interface
C# Inheritance
C# Namespace
C# Object
C# Delegate
C# Lambda
C# Event
C# Enum
C# Attribute
C# Generics
C# Preprocessor