Partial type
|
|
In computing, a partial type is a data type definition which spans multiple source code files. In object orientated programming this may be necessary for a variety of reasons: performance and cost can often prohibit the use of several separate classes; the use of code generating tools is increasing, and it is convenient to separate machine generated code from code written by the programmer.
Partial types are a feature of the C# 2.0 language. The syntax for creating a partial class definition is as follows:
SourceFile1.cs
public partial class ExampleClass
{
public void SomeFunction()
{
// ...
}
}
SourceFile2.cs
public partial class ExampleClass
{
public void SomeOtherFunction()
{
// ...
}
}
In C# versions before 2.0, this would cause a compiler error because the same class appears to be defined twice (and also because of the partial keyword). In C# 2.0 this is treated as a single class definition. Other new features of C# 2.0 include anonymous methods, iterators and generics (similar to templates in C++).
The use of partial classes has no effect on generated code (unless editor meta-data is emitted).
