Visual Basic .NET Language Creating classes


Example

Classes provide a way of creating your own types within the .NET framework. Within a class definition you may include the following:

  • Fields
  • Properties
  • Methods
  • Constructors
  • Events

To declare a class you use the following syntax:

Public Class Vehicle     
End Class

Other .NET types can be encapsulated within the class and exposed accordingly, as shown below:

Public Class Vehicle
     Private Property _numberOfWheels As Integer
     Private Property _engineSize As Integer

     Public Sub New(engineSize As Integer, wheels As Integer)
         _numberOfWheels = wheels
         _engineSize = engineSize
     End Sub

     Public Function DisplayWheelCount() As Integer
         Return _numberOfWheels
     End Function
End Class