VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > VB.net教程 >
  • vb.net类的属性定义,使用方式

Namespace mySpace
    Public Class MyClass1

        Private Property _myID As String
        Private Property _myName As String
        Private Property Y As Integer
        Public Property X As Integer


        Public Property myID As String
            Get
                Return _myID
            End Get
            Set(value As String)
                _myID = value
            End Set
        End Property
        Public Property myName As String
            Get
                Return _myName
            End Get
            Set(value As String)
                _myName = value
            End Set

        End Property

        Public Property mX As Interger
            Get
               X
            End Get
            Set(value As Inter)
               X=2*Y
            End Set

        End Property

    End Class
End Namespace

 

 

注释:这里定义为属性的意义     

1   通过私有属性来访问公有属性,达到安全控制的目的

2  通过私有属性来访问公有属性,还可以在赋值的时候,做一些限制或者特殊的处理,计算。达到对私有属性更高一层的控制。某一个属性的值改变了,自动触发另外一个属性的值。不用在外部通过事件的代码来实现。

 

作者:czf2505
转载自
https://blog.csdn.net/czf2505/article/details/16338401?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522160655021119724847197818%2522%252C%2522scm%2522%253A%252220140713.130102334..%2522%257D&request_id=160655021119724847197818&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~sobaiduend~default-3-16338401.pc_first_rank_v2_rank_v28&utm_term=VB.NET%E7%B1%BB&spm=1018.2118.3001.4449

相关教程