Visual Basic .NET/Classes

Introduction
The Class concept is the main foundation of Object Oriented Programming. In a world of Graphical User Interfaces and more complex programs, classes have become a very important part of programming.

To create a class, in the Solutions explorer, after a right click on the application, Add, then Class. Or select "Add Class..." from the Project menu of the menu bar.

Terminology
object: A unit that has its own properties and methods for a user to use at his or her discretion.

encapsulation: Lets the user of the class control the data and operations of a class that can be seen from other classes.

property: Represents a data value associated with an instance.

method: An operation that can be performed by the class.

constructor: The method that is called when an object of the class has been instantiated.

field: A variable at the class level.

Fields
Fields are variables that are inside a class but not inside functions, sub routines and properties. These variables are also not allowed to be called outside a class. Declaring these variables is simple, as shown in this segment of a class:

The class can call these variables up easily with " Me " calling. Look at this segment of a class to understand how:

Trying to call up a private field outside of a class will not work.

Constructors
When a new object of a class is declared, we can initialize the fields of a class. For example, look at this segment of a class:

Technically, a constructor with no parameters is called an Empty Constructor or a Default Constructor. A Constructor that has parameters is called a Custom Constructor.

Properties
Properties are divided into two categories: getters and setters. A getter returns a value from a class, much like how a function works and a setter sets a value into the class.

Because this class property is " Public ", we can access it from outside the class. If it was " Private ", it would be the complete opposite.

Methods
Methods are pretty much sub routines specific to a class. These can be called up as many or as little times as the programmer desires.

Instantiation
We use the keyword " New ":

Example Class
This is just an example of a class using all the above techniques:

Visual Basic .NET/Classes