VB.NET Object Oriented编程技巧有哪些

发布时间:2021-12-02 14:31:28 作者:小新
来源:亿速云 阅读:111

小编给大家分享一下VB.NET Object Oriented编程技巧有哪些,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!

VB.NET Object Oriented编程内功心法一
也就是在Class里加添属性(Properties)。有些属性的值数只限于读取而不能冩,有些就之能冩而不能读取;但一般都是两者兼施

Public Class ClassName  Private VeriableName As DataType  [Public | Private | Protected] [Property] PropertyName ( ) As DataType  Get  '// ...  Return VeriableName  End Get  Set (ByVal Value As DataType)  VeriableName = Value End Set  End Property  End Class

只能读取值数的属性:

Public Class ClassName  Private VeriableName As DataType  [Public | Private | Protected] [ReadOnly] [Property] PropertyName ( ) As DataType  Get  '// ...  Return VeriableName  End Get  End Property  End Class

只限于冩值数的属性:

Public Class ClassName  Private VeriableName As DataType   [Public | Private | Protected] [WriteOnly] [Property] PropertyName ( ) As DataType  Set (ByVal Value As DataType)  VeriableName = Value End Set  End Property  End Class

VB.NET Object Oriented编程内功心法二
怎样在Instantiate Class的同时宣告和执行某些函式,例如建立一个新的SqlConnection Object或者宣告变量等等。要达到这一点,我们就利用Class的Constructors函式了。以下就是在Class里添加 Constructor函式的语法。

Public Class CalssName  [Public] [Sub] New ( )  '// ...  End Sub  End Class

因为此是Object Oriented编程,所以也可以建立多个不同自变量的Constructor函式。但在此就跟编冩Overloads方法(Method)有点不同,那就是不需要用Overloads关键字来表示该函式就是Overloads函式。

Public Class CalssName  [Public] [Sub] New (Byval Arguement As DataType)  '// ...  End Sub  End Class

VB.NET Object Oriented编程内功心法三:
有了Contructor当然就要有Destructor嘛;世界所有物軆本来是双双对对。。。就连Object Oriented编程也一样,否则就不平衡了。而Destructor函式是在系统将要释放Object时所执行,所以一般Destructor都是用来解放在整个Object里所用过(宣告和建立)的资源。

Public Class ClassName  [Protected] [Overrides] [Sub] Finalize ( )  '// ...  End Sub  End Class

以上是“VB.NET Object Oriented编程技巧有哪些”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注亿速云行业资讯频道!

推荐阅读:
  1. VB.NET下载程序实现代码怎么编写
  2. 如何体现VB.NET System.IO在实际编程中的作用

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

vb.net

上一篇:如何在嵌入式产品中应用键值存储数据库

下一篇:tk.Mybatis插入数据获取Id怎么实现

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》