User Shared variable to count instance number : Shared « Class « VB.Net






User Shared variable to count instance number

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

1.Shared Method DemoShared Method Demo
2.Use Shared method to construct ObjectUse Shared method to construct Object
3.Class with all shared Member variablesClass with all shared Member variables
4.Class Shared VariableClass Shared Variable