VB.NET Constructor函式怎么用

2023-05-18,

这篇文章主要介绍VB.NET Constructor函式怎么用,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!

Object Oriented编程

也就是在Class里加添属性(Properties)。有些属性的值数只限于读取而不能写,有些就之能写而不能读取;但一般都是两者兼施

  1. Public Class ClassName  

  2. Private VeriableName As DataType  

  3.  

  4. [Public | Private | Protected] [Property] 
    PropertyName ( ) As DataType  

  5. Get  

  6. '// ...  

  7. Return VeriableName  

  8. End Get  

  9. Set (ByVal Value As DataType)  

  10. VeriableName = Value 

  11. End Set  

  12. End Property  

  13. End Class  

  14.  

  15. 只能读取值数的属性:  

  16. Public Class ClassName  

  17. Private VeriableName As DataType  

  18. [Public | Private | Protected] [ReadOnly] 
    [Property] PropertyName ( ) As DataType  

  19. Get  

  20. '// ...  

  21. Return VeriableName  

  22. End Get  

  23. End Property  

  24. End Class  

  25.  

  26. 只限于冩值数的属性:  

  27. Public Class ClassName  

  28. Private VeriableName As DataType  

  29.  

  30. [Public | Private | Protected] [WriteOnly] 
    [Property] PropertyName ( ) As DataType  

  31. Set (ByVal Value As DataType)  

  32. VeriableName = Value 

  33. End Set  

  34. End Property  

  35. End Class 

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

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

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

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

以上是“VB.NET Constructor函式怎么用”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注本站行业资讯频道!

《VB.NET Constructor函式怎么用.doc》

下载本文的Word格式文档,以方便收藏与打印。