(VB.Net)Structure结构体

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u011978079/article/details/89332991

定义:声明结构的名称,并引入的变量、属性、事件和结构包含的过程的定义

语法:

[<attributelist>][accessmodifier][Shadows][Partial] Structure name[(Of typelist)]
    [Implements interfacenames]
    [datamember interfacenames]
    [methodmemberdeclarations]
End Structure

'attributelist:属性列表,可选。
'accessmodifier:结构体的访问级别,可选值:Public,Protected,Friend,Private,Protected Friend,Private Protected,可选。
'Shadows:声明的元素重新声明并隐藏具有相同名称的元素或在其基类中的重载元素集,可选。
'Partial:指结构的部分定义,可选。
'name:结构体的名称,可选。
'Of:指定这是一个泛型结构,可选。
'typelist:结构的类型参数列表。
'Implements:此结构实现一个或多个接口的成员,可选。
'interfacenames:此结构实现接口的名称
'datamember declarations:0个或多个(Const,Dim,Enum,或Event)语句声明的数据成员的结构
'methodmember declarations:0个或多个声明Function,Operator,Property或Sub过程,充当方法成员的结构。
'End Structure:终止Structure定义

示例:

Public Structure employee
    
    Public firstName As String
    Public middleName As String
    Public lastName As String
    
    Friend employeeNumber As Integer
    Friend workPhone As Long
    
    Private homePhone As Long
    Private level As Integer
    Private salary As Double
    Private bonus As Double
    
    Friend Sub calculateBonus(ByVal rate As Single)
        bonus = salary * CDbl(rate)
    End Sub
    
    Friend ReadOnly Property eligible() As Boolean
        Get
            Return level >= 25
        End Get
    End Property
    
    Public Event changedWorkPhone(ByVal newPhone As Long)
End Structure

 

猜你喜欢

转载自blog.csdn.net/u011978079/article/details/89332991
0条评论
添加一条新回复