中国IT动力,最新最全的IT技术教程
最新100篇 | 推荐100篇 | 专题100篇 | 排行榜 | 搜索 | 在线API文档 | 网通镜像
首 页 | 程序开发 | 操作系统 | 软件应用 | 图形图象 | 网络应用 | 精文荟萃 | 教育认证 | 硬件维护 | 未整理篇 | 站长教程
ASP JS PHP工程 ASP.NET 网站建设 UML J2EESUN .NET VC VB VFP 网络维护 数据库 DB2 SQL2000 Oracle Mysql
服务器 Win2000 Office C DreamWeaver FireWorks Flash PhotoShop 上网宝典 CorelDraw 协议大全 网络安全 微软认证
硬件维护  CPU  主板  硬盘  内存  显卡  显示器  键盘鼠标  声卡音箱  打印机  机箱电源  BIOS  网卡  C#  Java  Delphi  vs.net2005
  当前位置:> 程序开发 > 编程语言 > .NET > 临时文章
[译]Visual Basic 2005在语言上的增强(九)部分类型
作者:未知 时间:2005-07-27 21:30 出处:CSDN 责编:chinaitpower
              摘要:[译]Visual Basic 2005在语言上的增强(九)部分类型
部分类型允许在不同的源文件中定义同一个类型。在其中一个文件中可以使用普通方式进行的类型定义(作者说的“普通”的意思是不需要使用Partial关键字,涕淌注):
Public Class TestPartial
    '代码实现……
End Class

而在其他的源文件中,你必须使用Partial关键字来告诉编译器,这其中的代码是对原始类定义的一个扩展:
Partial Public Class TestPartial
    '代码实现……
End Class

类中由IDE生成的代码被标以Partial关键字,并且和用户填写的代码分离开来。你在工程中添加一个名为TestForm的窗体,来看看生成的源文件。你可能很惊讶是吧,因为除了窗体类声明的空框架之外就空空如也了。从前那些“Windows窗体自动生成的代码”区域里那些设计器生成的代码到哪儿去了呢?

现在,设计器生成的代码都被存放在TestForm.Designer.vb文件中,你可以点击解决方案浏览器工具条上的Show All Files按键来阅读这个文件。你不应该修改这个文件中的代码(实际上你是可以修改的,只是不推荐你这么做,涕淌注),但是,如果你想在设计器文件被再次生成时保留下一些东西,你可以把需要的代码复制粘贴到TestForm.vb文件中。

工程小组可以利用部分类的优点,为每一个开发人员分配编写同一个类的某一个部分类文件的任务。多人开发已经不再需要对同一个源文件进行共享访问了,因为你们现在可以把同一个类的定义分散到多个源文件中。


@以下是原文供网友们参考@

Partial Types

Partial types allow definition of a single type across multiple source files. The type definition has a normal declaration in one file:
Public Class TestPartial
    'implemention...
End Class

In other source files, you use the Partial keyword to tell the compiler that this code is a continuation of the original class definition:
Partial Public Class TestPartial
    'implemention...
End Class

Code in classes generated by designers in the IDE is marked with the Partial keyword, and is separated from user code. Add a form named TestForm to a project and look at the resulting source file. You may be surprised to see that it's empty except for the form's class declaration. Where's all the designer-generated code that used to go inside the Windows Form Designer Generated Code region?

The designer-generated code is now placed in file TestForm.designer.vb, which you can see by clicking the Show All Files button in the Solution Explorer toolbar. You shouldn't change the code in this file, but you can copy and paste what you need into the TestForm.vb file if you want to preserve something when the designer file is later regenerated.

Project teams can take advantage of partial classes by giving each developer a file containing their portion of the class. Multiple developers no longer need to share access to the same source files since you can now separate a class definition into multiple source files.
关闭本页
 
首页 | 投资与合作 | 服务条款 | 隐私政策 | 收藏本站 | 设为首页 | 新用户注册 | 免责声明 | 使用帮助
Copyright ©2005-2008 chinaitpower.com All rights reserved. www.chinaitpower.com 版权所有