Partial type is a new feature introduced in .Net 2.0 (VS2005). Using Partial type you can define a
single class in multiple files (more than one files) at compilation time these
classes are combined into a single class. You can apply partial modifier on a
class or a struct, or an interface.
Partial modifier is not available on delegate or enumeration
declarations.
There are a
few things that you should be careful about when writing code for partial
classes:
·
All
the partial types must be defined within a same assembly and module.
·
Method
signatures (return type, name of the method, and parameters) must be unique for
the aggregated typed (which was defined partially).
·
The
partial types must have the same accessibility.
·
Inheritance
at any partial type applies to the entire class.
·
If
any part is sealed, the entire class is sealed.
·
If
any part is abstract, the entire class is abstract.
Example
//partial class
public partial class Employee
{
public
virtual void GetEmployeeNo();
}
public partial class Employee
{
public
virtual void GetEmployeeName();
}
//Derived class
public class Department : Employee
{
public
void getEmployeeDetails()
{
GetEmployeeNo ();
GetEmployeeName ();
}
}
No comments:
Post a Comment