Mega Code Archive

 
Categories / VB.Net Tutorial / Class Module
 

Use Property to set private data

Module Module1     Sub Main()         Dim TheObject As New TheClass         Console.WriteLine("ThePublicData holds """ & TheObject.ThePublicData & """")         Console.WriteLine("TheMethod returns """ & TheObject.TheMethod() & """")         Console.WriteLine("TheProperty holds """ & TheObject.TheProperty & """")     End Sub End Module Class TheClass     Public ThePublicData = "Hello there!"     Private TheInternalData As String = "Hello there!"     Function TheMethod() As String         Return "Hello there!"     End Function     Public Property TheProperty() As String         Get             Return TheInternalData         End Get         Set(ByVal Value As String)             TheInternalData = Value         End Set     End Property End Class ThePublicData holds "Hello there! TheMethod returns "Hello there! TheProperty holds "Hello there!