转至繁体中文版     | 网站首页 | 图文教程 | 资源下载 | 站长博客 | 图片素材 | 武汉seo | 武汉网站优化 | 
最新公告:     敏韬网|教学资源学习资料永久免费分享站!  [mintao  2008年9月2日]        
您现在的位置: 学习笔记 >> 图文教程 >> 软件开发 >> VB.NET程序 >> 正文
[译]Visual Basic 2005在语言上的增强(九)部分类型         ★★★★

[译]Visual Basic 2005在语言上的增强(九)部分类型

作者:闵涛 文章来源:闵涛的学习笔记 点击数:570 更新时间:2009/4/23 15:41:59
部分类型允许在不同的源文件中定义同一个类型。在其中一个文件中可以使用普通方式进行的类型定义(作者说的“普通”的意思是不需要使用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.


[VB.NET程序]Visual Basic 6 逆向工程与反逆向工程 (2)  [VB.NET程序]Visual Basic 6 逆向工程与反逆向工程 (1)
[VB.NET程序]用Visual Basic创建复杂窗体  [VB.NET程序]Visual Basic的类对于面向对象的支持
[VB.NET程序]如何在Visual Basic 6.0 中连接加密的Access数据库  [VB.NET程序]使用Visual Basic操纵XML文档
[VB.NET程序]Visual Basic.Net连各种数据库的几种方法  [VB.NET程序]Visual Basic .NET资源工具包
[VB.NET程序]效率提高两倍!——Visual Basic.net 新力量  [VB.NET程序]复杂和高效——Visual Basic.net新力量
教程录入:mintao    责任编辑:mintao 
  • 上一篇教程:

  • 下一篇教程:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
      注:本站部分文章源于互联网,版权归原作者所有!如有侵权,请原作者与本站联系,本站将立即删除! 本站文章除特别注明外均可转载,但需注明出处! [MinTao学以致用网]
      网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)

    同类栏目
    · C语言系列  · VB.NET程序
    · JAVA开发  · Delphi程序
    · 脚本语言
    更多内容
    热门推荐 更多内容
  • 没有教程
  • 赞助链接
    更多内容
    闵涛博文 更多关于武汉SEO的内容
    500 - 内部服务器错误。

    500 - 内部服务器错误。

    您查找的资源存在问题,因而无法显示。

    | 设为首页 |加入收藏 | 联系站长 | 友情链接 | 版权申明 | 广告服务
    MinTao学以致用网

    Copyright @ 2007-2012 敏韬网(敏而好学,文韬武略--MinTao.Net)(学习笔记) Inc All Rights Reserved.
    闵涛 投放广告、内容合作请Q我! E_mail:admin@mintao.net(欢迎提供学习资源)

    站长:MinTao ICP备案号:鄂ICP备11006601号-18

    闵涛站盟:医药大全-武穴网A打造BCD……
    咸宁网络警察报警平台