The System Namespace VB.NET

The System namespace contains classes for such broad ranging things as:

  • Data types
  • Data type conversions
  • Method-parameter manipulation
  • Events and event handlers
  • Mathematics
  • Program invocation
  • Application-environment management

Data Type Conversion

To illustrate data type conversion, the System namespace defines a class called Convert. If you check the documentation, you'll find that one of the methods of the Convert class is ToBoolean. The documentation lists the following for ToBoolean:

As you can see, there are many ToBoolean functions each one with a different argument signature to take care of converting various data types to Boolean.

Now, just for exercise, we can write:

Because the System namespace is always available (or if we are programming outside of Visual Studio, we can import it using the Imports statement), we can omit the System qualifier and write:

The Convert class contains methods for converting data to the standard Visual Basic data types, as well as to the data types supported by the .NET Framework but not wrapped by Visual Basic, such as the unsigned-integer data types. The most important of these methods are shown.

Table : Members of the System.Convert class

Table : Members of the System.Convert class

The Array Class

The Array class contains useful methods for dealing with arrays. For instance, the Array object has a Sort method (at last) that sorts the elements of an array. Here is an example:

Some of the more important methods of the Array class are shown.

Table : Members of the System.Convert class

The Math Class

The Math class has a number of mathematical-function methods (such as trigonometric functions), as well as some more useful methods, such as Max and Min. Therefore, we can just write:

The Math ClassThe Math Class

The String Class

The String class implements a collection of methods for string manipulation, including methods for locating substrings, concatenation, replacement, padding, trimming, and so on. One interesting method is Insert, which inserts a new string into an existing string.

The VB .NET String data type is equivalent to the System.String class, so we can apply the methods of System.String directly to VB strings, as in:

This displays the message "To be or not to be."

The String Class
The String Class

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd Protection Status

VB.NET Topics