c# - 部分是什么意思?

标签 c# syntax partial-classes

public partial class Form1 : Form

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

最佳答案

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

查看此 MSDN article, "Partial Class Definitions"了解更多信息:

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:

  • When working on large projects, spreading a class over separate files allows multiple programmers to work on it simultaneously.
  • When working with automatically generated source, code can be added to the class without having to recreate the source file. Visual Studio uses this approach when creating Windows Forms, Web Service wrapper code, and so on. You can create code that uses these classes without having to edit the file created by Visual Studio.

您可能在创建表单时指的是 Visual Studio 的默认行为。这允许将表单的定义分为 拥有并可以修改的文件,以及Visual Studio 拥有的文件 (Form1.Designer.cs)。这避免了 很多 我们在 Visual Studio 2002 和 2003 中看到的令人头疼的问题,当时开发人员和 IDE 在编辑时总是越过彼此的脚趾。

关于c# - 部分是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3861171/

相关文章:

C# 数据结构 : What type of collection should I use?

c# - Visual Studio 2010 解决方案文件夹中的未知 Index.dat 和 Storage.dat 文件

c# - 如何在 C# 中为 XPath 添加命名空间?

c# - 支持/反对使用部分类进行测试的原因?

c# - 事件处理程序位于与 MainWindow 不同的类中

c# - 成员名称不能与其包含部分类的封闭类型相同

c# - 如何从重新实现 GetHashCode 的类中获取原始哈希码?

javascript - php脚本回显中的双引号

php - 如何在MySQL数据库中插入可变数据

list - Lisp 递归归并排序与升序?