Local type (partial)
I personally understand that is to divide a whole into parts.
We use a piece of code to understand
/// <summary>
/// 定义MyClass类的一个部分
/// </summary>
public partial class MyClass
{
public void RtuStrin()
{
}
}
/// <summary>
/// 定义MyClass类的另一个部分
/// </summary>
/// 此地方不用加public,因为在前边一个部分上已加上了public
partial class MyClass
{
public int IPartialValue;
}
class Program
{
static void Main(string[] args)
{
//实例化类
//此时MyClass类是由两分MyClass的部分组成即 "public partial class MyClass"+" partial class MyClass"
MyClass myCa = new MyClass();
//调用类的字段即"partial class MyClass"中的字段
myCa.IPartialValue = 10;
//调用类的方法即"public partial class MyClass"中的方法
myCa.RtuStrin();
}
}
Below I look for articles on the web (from)
1. What is a local type?
C # 2.0 introduces the concept of a local type. A local type allows us to divide a class, struct, or interface into several parts and implement it in several different. cs files, respectively.
The local type applies to the following situations:
(1) The type is particularly large and should not be implemented in a single file.
(2) A part of a type of code generated by the Automation tool is not appropriate to mix with the code we write ourselves.
(3) Many people need to cooperate to write a class.
A local type is a compilation of a pure language layer that does not affect any execution mechanism--in fact, the C # compiler still merges local types of parts into a complete class at compile time.
public partial class Program
{
static void Main(string[] args)
{
}
}
partial class Program
{
public void Test()
{
}
}