User Shared variable to count instance number
Imports System.IO
Module Module1
Sub Main()
Dim p As New Professor()
Console.WriteLine("count {0}", p.Count)
Dim pp As New Professor()
Console.WriteLine("count {0}", pp.Count)
End Sub
End Module
Class Professor
Public Shared Count As Integer = 0
Public Name As String
Private Age As Integer
Public OfficeNumber As String
Private HomePhone As String
Public Sub New()
Count = Count + 1
End Sub
End Class
Related examples in the same category