Export (0) Print
Expand All

© 2004 Microsoft Corporation. All rights reserved.

Figure 1 Class with Shared Members
Class Class1
  ' instance members
  Private objectID As Integer
  ReadOnly Property ObjectInfo() As String
    Get
      Return "Object #" & CStr(objectID)
    End Get
  End Property
  ' shared members
  Private Shared objectCount As Integer
  Shared Function GetNextObject() As Class1
    objectCount += 1
    Dim temp As New Class1()
    temp.ObjectID = objectCount
    Return temp
  End Function
End Class
Figure 2 With and Without Default Constructor
Class ClassA
  Private field1 As String
  Overloads Sub New()
    field1 = "some default value"
  End Sub
  Overloads Sub New(s As String)
    field1 = s
  End Sub
End Class

Class ClassB
  Private field1 As String
  Sub New(s As String)
    field1 = s
  End Sub
End Class
Figure 3 Initializing Shared and Instance Members
Class Class2
  ' shared members  
  Public Shared s1 As Integer = 10
  Public Shared s2 As Integer
  Shared Sub New()
    s2 = 10
  End Sub
  ' instance members
  Public i1 As Integer = 10
  Public i2 As Integer
  Sub New()
    i2 = 10
  End Sub
End Class
Show:
© 2015 Microsoft