部分类和继承

编程入门 行业动态 更新时间:2024-10-25 12:21:54
本文介绍了部分类和继承的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

公共部分抽象类() { } 这个类与其他类有什么不同,部分是什么?此类中的函数

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

更多推荐

部分类和继承

本文发布于:2023-11-05 19:08:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1561612.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!