部分类和继承 [英] partial classes and inheritance

查看:64
本文介绍了部分类和继承的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

公共部分抽象类()

{

}

这个类与其他类有什么不同,部分是什么?此类中的函数

public partial abstract class()
{
}
how is this class different from any other classes, partial what is it's main function in this class

推荐答案

部分关键字不会以任何实际方式影响该类,它只是允许在多个源文件中定义它。如果类变大,并且你想要更好地组织它,或者你想将它拆分成逻辑组,例如WinForms表单 - 这是同一个类的两个部分类文件:myClass.cs和myClass.Designer.cs将您编写的代码与Visual Studio编写的代码分开。

为了使用,所有部分类文件必须将该类声明为部分。



它对课程没有任何其他影响。
The partial keyword doesn't affect the class in any real way, it just allows it to be defined in more than one source file. This is handy if the class is getting large, and you want to organise it better, or if you want to split it into logical groups, such as a WinForms form - which is two partial class files for the same class: myClass.cs and myClass.Designer.cs to separate the code you write from the code Visual Studio writes.
In order to be used, all partial class files must declare the class as partial.

It has no other effect on the class whatsoever.


简单来说,部分类跨越多个文件。例如,如果你使用过Windows Forms Application,你可能已经注意到一个designer.cs文件,这只是机器生成的C#代码是分开的

它对班级没有影响。



MSDN [ ^ ]:

In a simple word, "Partial classes span multiple files." For example, If you've worked with Windows Forms Application, you might have noticed one designer.cs file, that is nothing but The machine-generated C# code is separated.
It has no effect on class.

As per MSDN [^]:
Quote:

partial关键字表示可以在命名空间中定义类,结构或接口的其他部分。所有部分都必须使用partial关键字。所有部件必须在编译时可用,以形成最终类型。所有部件必须具有相同的可访问性,例如公共,私人等。

The partial keyword indicates that other parts of the class, struct, or interface can be defined in the namespace. All the parts must use the partial keyword. All the parts must be available at compile time to form the final type. All the parts must have the same accessibility, such as public, private, and so on.



-KR


-KR


这篇关于部分类和继承的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆