Getter/Setter example
Posted: 5/14/2005 10:27:32 PM
By: Comfortably Anonymous
Times Read: 1,977
0 Dislikes: 0
Topic: Programming: .NET Framework
Instead of defining tedious, Java-like (.getValue() /.setValue()) getters and setters, it's a lot quicker to just define a property, then use that property in your definition of the class:

' Declaration of private value that will be updated by the
' "Getter/Setter" property code below rather than giving
' direct access to the private variable.
Private _SomeValue as string

' The code is for interacting with the private variable
Public Property SomeValue() As String
  Get
    Return _SomeValue ' Use same name with an underscore for the private value
  End Get
  Set(ByVal Value As String)
    _SomeValue = Value
  End Set
End Property

' Setting the value:
Me.User = ""

' Getting the value:
SomethingElse = Me.User

Much cleaner than that archaic Java language!
Rating: (You must be logged in to vote)