Classes and Objects
Generally speaking, a class is a software component that defines and implements one or more interfaces. (Strictly speaking, a class need not implement all the members of an interface. We discuss this later when we talk about abstract members.) In different terms, a class combines data, functions, and types into a new type. Microsoft uses the term type to include classes.
Class Modules in VB.NET
Under Visual Studio.NET, a VB class module is inserted into a project using the Add Class menu item on the Project menu. This inserts a new module containing the code:
Public Class ClassName End Class
Although Visual Studio stores each class in a separate file, this
isn’t a requirement. It is the
Class...End
Class construct that marks the beginning and end
of a class definition. Thus, the code for more than one class as well
as one or more code modules (which are similarly delimited by the
Module...End Module construct)
can be contained in a single source code file.
The CPerson class defined in the next section is an example of a VB class module.
Class Members
In VB.NET, class modules can contain the following types of members:
- Data members
This includes member variables (also called fields) and constants.
- Event members
Events are procedures that are called automatically by the Common Language Runtime in response to some action that occurs, such as an object being created, a button being clicked, a piece of data being changed, or an object going out of scope.
- Function members ...
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.
Read now
Unlock full access