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

Defining a Class in Visual Basic .NET

A class is a user-defined data type. Its declaration is similar to the declaration of structures. You can declare it as part of a module; however, due to the fact that classes tend to be much larger (have more lines of code) than structures, they are usually declared in separate files (using the same .vb extension).

Create a new console project and give it the suggestive name ClassExample1. From the Project menu select Add Class and change the filename from Class1.vb to Horse.vb. Enter the lines of code shown in bold in the following example:

Public Class Horse
   Public m_name As String
						Public m_color As String
						Public m_height As Single
End Class

This is a class definition. Apparently there are no major differences ...

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