2013年10月28日 星期一

簡單的使用類別中的類別下的屬性

參考引用來源
--
  1. Public Class Factory
  2.  
  3. Private sAddress As String
  4. Private sTEL As String
  5. Private objEmp As New Employees
  6.  
  7. Public Property Address() As String
  8. Get
  9. Return sAddress
  10. End Get
  11. Set(ByVal value As String)
  12. sAddress = value
  13. End Set
  14. End Property
  15.  
  16. Public Property TEL() As String
  17. Get
  18. Return sTEL
  19. End Get
  20. Set(ByVal value As String)
  21. sTEL = value
  22. End Set
  23. End Property
  24.  
  25. Public Property Employees() As Employees
  26. Get
  27. Return objEmp
  28. End Get
  29. Set(ByVal value As Employees)
  30. objEmp = value
  31. End Set
  32. End Property 
End Class

  1. Public Class Employees
  2. Private bWork As Boolean
  3. Private sName As String
  4.  
  5.  
  6. Public Property Work() As Boolean
  7. Get
  8. Return bWork
  9. End Get
  10. Set(ByVal value As Boolean)
  11. bWork = value
  12. End Set
  13. End Property
  14.  
  15. Public Property Name() As String
  16. Get
  17. Return sName
  18. End Get
  19. Set(ByVal value As String)
  20. sName = value
  21. End Set
  22. End Property
  23.  
End Class

--
用法:
  1. Dim ft As New Factory
  2. ft.Address = "地球村台灣區台中路112號"
  3.  
  4. '簡短寫法
  5. With ft.Employees
  6. .Name = "Tom"
  7. .Work = False
  8. End With
  9. '或用一般寫法
  10. ft.Employees.Name = "Tom" 
 ft.Employees.Work = False

沒有留言:

張貼留言