Property Question

silverstormboy

Newcomer
Joined
Nov 22, 2002
Messages
18
Location
Singapore
hi , I have a question regarding property in vb.net.

for ex:

i have a statusbar control in the form name statusBar and value text = "".

then i create the property as follows:
Visual Basic:
Public Property StatusText() as String
   Get
      Return statusBar.Text
   End Get
   Set(ByVal Value As String)
      statusBar.Text = Value
   End Set
End Property

after that, to call this property :
Visual Basic:
StatusText = "Ready"

What is the use of property in vb.net?
why can't we just type:
Visual Basic:
   statusBar.Text = "Ready"
instead of creating the property?

Some book say that property is very useful and important in vb.net but I do not see it. Please give me advice about this , Thanks.
 
The only reason that I can see why you would do it like that is so that you can set the StatusText property from outside of the form.
 
Exactly. Properties are an interface between private fields and the outside world. If you have a control that paints itself, you need a text property, so that when the user calls the Set method, you know to redraw your control.

For more info on properties, I suggest you read the documentation.
 
Back
Top