温馨提示×

温馨提示×

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

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

VB.NET中如何使用类属性

发布时间:2021-07-20 11:41:17 来源:亿速云 阅读:202 作者:Leah 栏目:编程语言

本篇文章给大家分享的是有关VB.NET中如何使用类属性,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。

VB.NET类属性1、

  1. Public Property Rank() As String 
    '注意这里的属性名后面有个括号  

  2. Get  

  3. Return strPos  

  4. End Get  

  5. Set(ByVal value As String)  

  6. strPos = value 

  7. End Set  

  8. End Property 

VB.NET类属性2、

  1. Public ReadOnly Property rHobby() As 
    String 'Readonly要在Property前面  

  2. Get  

  3. Dim i As Integer  

  4. Dim s As String  

  5. s = Join(strHobby, ",") 
    '这个函数就是用来连接数组中的字符串的  

  6. Return s  

  7. End Get  

  8. End Property 

VB.NET类属性3、

  1. '这是定义索引器呀!  

  2. Public ReadOnly Property indexHobby
    (ByVal index As Integer) As String  

  3. Get  

  4. If (strHobby Is Nothing) Or (index > 
    UBound(strHobby)) Then  

  5. '注意到上面的UBound()了没?还有LBound()!  

  6. '它们所在的命名空间是Microsoft.VisualBasic  

  7. Return Nothing  

  8. End If  

  9. Return strHobby(index)  

  10. End Get  

  11. End Property 

VB.NET类属性4、

  1. Public WriteOnly Property wHobby() 
    As String  

  2. Set(ByVal value As String)  

  3. If value Is Nothing Then  

  4. If Not (strHobby Is Nothing) And 
    strHobby.GetLength(0) > 1 Then  

  5. ReDim Preserve strHobby(UBound
    (strHobby) - 1)  

  6. End If  

  7. Else  

  8. If strHobby Is Nothing Then  

  9. ReDim strHobby(0)  

  10. Else  

  11. ReDim Preserve strHobby(UBound
    (strHobby) + 1)  

  12. End If  

  13. strHobby(UBound(strHobby)) = value  

  14. End If  

  15. End Set  

  16. End Property 

5、

  1. Default Public Property Words
    (ByVal index As Integer) As 
    String'注意Default  

  2. Get '注意到参数了吗?使用这个属性的时候,
    就跟实现了索引器效果一样。
    <ClassObj(index)> 

  3. Words = theWords(index)  

  4. End Get  

  5. Set(ByVal value As String)  

  6. theWords(index) = value  

  7. End Set  

  8. End Property 

以上就是VB.NET中如何使用类属性,小编相信有部分知识点可能是我们日常工作会见到或用到的。希望你能通过这篇文章学到更多知识。更多详情敬请关注亿速云行业资讯频道。

向AI问一下细节

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

AI