与抽象类相比,使用分部类有什么好处? [英] What are the benefits to using a partial class as opposed to an abstract one?

查看:36
本文介绍了与抽象类相比,使用分部类有什么好处?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在阅读编程 Microsoft® Visual C#® 2008:语言以更好地理解 C# 以及可以用它做什么.我遇到了我已经从 ASP.Net 的 Page 类中遇到的部分类.

I have been reading Programming Microsoft® Visual C#® 2008: The Language to get a better understanding of C# and what can be done with it. I came across partial classes which I had already encountered from ASP.Net's Page class.

对我来说,您似乎可以对抽象类和被覆盖的类做部分类所做的事情.显然,一个团队将通过抽象方法控制接口,但无论如何你们都会相互依赖.如果目标是协作,那么源代码控制和其他工具就不能解决这个问题.

To me it seems that you can do what partial classes do with an abstract class and an overridden one. Obviously one team will be in control of the interface via the abstract methods but you would be relying on each other anyway. And if the goal is collaboration then isn't that what source control and other tools solve.

我只是错过了部分课程的重点.也有人可以提供现实世界的用途.

I am just missing the point to a partial class. Also could someone provide a real world use.

推荐答案

部分类与对象继承无关.分部类只是将定义类的源代码拆分为单独文件的一种方式(例如,当您在 Windows 窗体应用程序中创建新表单时会这样做 - 一个文件是您的"代码,另一个文件是 .designer.cs包含VS2008为你管理的代码).

Partial classes have nothing to do with object inheritance. Partial classes are just a way of splitting the source code that defines a class into separate files (this is for example done when you create a new form in your Windows Forms application - one file is "your" code, another file .designer.cs contains the code that VS2008 manages for you).

这篇关于与抽象类相比,使用分部类有什么好处?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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