部分是什么意思? [英] What does the partial mean?

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

问题描述

public partial class Form1 : Form

这个声明中的部分是什么意思?我知道我们有一个继承自 Form 的类 Form1.但是部分是什么意思?

What does the partial in this declaration mean? I understand we have a class Form1 that inherits from Form. But what does the partial mean?

推荐答案

它允许您将类的定义拆分为两个或多个单独的文件.

It allows you to split the definition of your class into two or more separate files.

请参阅此 MSDN 文章部分类定义" 了解更多信息:

See this MSDN article, "Partial Class Definitions" for more information:

可以在两个或多个源文件上拆分类或结构或接口的定义.每个源文件都包含一个类定义的部分,在编译应用程序时将所有部分组合在一起.有几种情况需要拆分类定义:

It is possible to split the definition of a class or a struct, or an interface over two or more source files. Each source file contains a section of the class definition, and all parts are combined when the application is compiled. There are several situations when splitting a class definition is desirable:

  • 在处理大型项目时,将一个类分散到单独的文件中可以让多个程序员同时处理它.
  • 使用自动生成的源代码时,无需重新创建源文件即可将代码添加到类中.Visual Studio 在创建 Windows 窗体、Web 服务包装器代码等时使用这种方法.您可以创建使用这些类的代码,而无需编辑由 Visual Studio 创建的文件.

您可能指的是创建表单时 Visual Studio 的默认行为.这允许在拥有并可以修改的文件和Visual Studio拥有的文件(Form1.Designer.cs)之间拆分表单定义.这避免了很多我们在 Visual Studio 2002 和 2003 中看到的令人头疼的问题,因为开发人员和 IDE 会在编辑过程中一直互相推诿.

You're likely referring to the default behavior of Visual Studio when creating forms. This allows the definition of the form to be split between the file that you own and can modify, and the file that Visual Studio owns (Form1.Designer.cs). This avoids a lot of headaches we saw with Visual Studio 2002 and 2003, when the developer and the IDE would step over each other's toes all the time with their edits.

这篇关于部分是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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