2014年4月30日 星期三

VB.NET 簡單的使用類別中的類別下的屬性

參考引用來源
--

 Public Class Factory

    Private sAddress As String
    Private sTEL As String
    Private objEmp As New Employees

    Public Property Address() As String
        Get
            Return sAddress
        End Get
        Set(ByVal value As String)
            sAddress = value
        End Set
    End Property

    Public Property TEL() As String
        Get
            Return sTEL
        End Get
        Set(ByVal value As String)
            sTEL = value
        End Set
    End Property

    Public Property Employees() As Employees
        Get
            Return objEmp
        End Get
        Set(ByVal value As Employees)
            objEmp = value
        End Set
    End Property
End Class

Public Class Employees
    Private bWork As Boolean
    Private sName As String


    Public Property Work() As Boolean
        Get
            Return bWork
        End Get
        Set(ByVal value As Boolean)
            bWork = value
        End Set
    End Property

    Public Property Name() As String
        Get
            Return sName
        End Get
        Set(ByVal value As String)
            sName = value
        End Set
    End Property

End Class

Dim ft As New Factory
 ft.Address = "地球村台灣區台中路112號"

 '簡短寫法
 With ft.Employees
     .Name = "Tom"
     .Work = False
 End With
 '或用一般寫法
 ft.Employees.Name = "Tom"
 ft.Employees.Work = False


沒有留言:

張貼留言