Skip to Content
Programming Visual Basic .NET
book

Programming Visual Basic .NET

by Dave Grundgeiger
December 2001
Beginner
464 pages
13h 51m
English
O'Reilly Media, Inc.
Content preview from Programming Visual Basic .NET

Classes

A class is one form of data type. As such, a class can be used in contexts where types are expected—in variable declarations, for example. In object-oriented design, classes are intended to represent the definition of real-world objects, such as customer, order, product, etc. The class is only the definition, not an object itself. An object would be a customer, an order, or a product. A class declaration defines the set of members—fields, properties, methods, and events—that each object of that class possesses. Together, these members define an object’s state, as well as its functionality. An object is also referred to as an instance of a class. Creating an object of a certain class is called instantiating an object of the class.

Consider the class definition in Example 2-4.

Example 2-4. A class definition

Public Class Employee

   Public EmployeeNumber As Integer
   Public FamilyName As String
   Public GivenName As String
   Public DateOfBirth As Date
   Public Salary As Decimal

   Public Function Format(  ) As String
      Return GivenName & " " & FamilyName
   End Function
   
End Class

The code in Example 2-4 defines a class called Employee. It has five public fields (also known as data members ) for storing state, as well as one member function . The class could be used as shown in Example 2-5.

Example 2-5. Using a class

Dim emp As New Employee( ) emp.EmployeeNumber = 10 emp.FamilyName = "Rodriguez" emp.GivenName = "Celia" emp.DateOfBirth = #1/28/1965# emp.Salary = 115000 Console.WriteLine("Employee ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Programming Visual Basic .NET, Second Edition

Programming Visual Basic .NET, Second Edition

Jesse Liberty

Publisher Resources

ISBN: 0596000936Supplemental ContentCatalog PageErrata