VB.net Program to Count the Total Created Objects Using a Shared Member

You are currently viewing VB.net Program to Count the Total Created Objects Using a Shared Member

VB.Net program to count the total created objects using a shared member

'VB.net program to count the total created objects 
'using a shared member.

Module Module1
    Class Sample
        Shared count As Integer
        Sub New()
            count = count + 1
        End Sub
        Sub ObjectCount()
            Console.WriteLine("Total objects: {0}", count)

        End Sub
    End Class

    Sub Main()
        Dim obj1 As New Sample()
        Dim obj2 As New Sample()
        Dim obj3 As New Sample()

        obj3.ObjectCount()
    End Sub
End Module
Total objects: 3
Press any key to continue . . .

Ranjith Kumar

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply