O'Reilly logo

Visual Basic® .NET by Example by Bob Donald, Gabriel Oancea

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using Properties

Properties can be used exactly as the fields are used. For example, if you use the class you defined previously, you could write code as shown:

Module Module1
   Sub Main()
      Dim h As Horse = New Horse("Bucefalus", "black", 2)
      h.height = 1.9
      Console.Out.WriteLine("The height is {0} ", h.height)
   End Sub
End Module

You construct a new Horse object and then you set its height to 1.9, and you output the value of the height property to the console. The second line in Sub Main (h.height = 1.9) will call the property procedure and execute its Set block. The Value implicit variable will be set to 1.9. That means it would pass verification using the If statement and will set the m_height field value to be 1.9.

Next you read the value (execute ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required