Namespaces - VB.NET

The notion of a namespace plays a fundamental role in the .NET Framework. In general, a namespace is a logical grouping of types for the purpose of identification. For example, imagine that in a certain business there is an executive named John Smith, a secretary named John Smith, and a custodian named John Smith.

In this case, the name John Smith is ambiguous. When the paymaster stands on a table and calls out the names of people to receive their pay checks, the executive John Smith won't be happy if he rushes to the table when the paymaster calls out his name and the envelope contains the custodian John Smith's pay check.

To resolve the naming ambiguity, the business can simply define three namespaces: Executive, Secretarial, and Custodial. Now the three individuals can be unambiguously referred to by their fully qualified names:

  • Executive.John Smith
  • Secretarial.John Smith
  • Custodial.John Smith

The .NET Framework Class Library (FCL), which we look at in more detail in Chapter 5, consists of several thousand classes and other types (such as interfaces, structures, and enumerations) that are divided into over 90 namespaces. These namespaces provide basic system services, such as:

  • Basic and advanced data types and exception handling (the System namespace)
  • Data access (the System.Data namespace)
  • User-interface elements for standard Windows applications (the System.Windows.Forms namespace)
  • User-interface elements for web applications (the System.Web.UI namespace)

In fact, the VB .NET language itself is implemented as a set of classes belonging to the Microsoft.VisualBasic namespace. (The C# and JScript languages are also implemented as a set ofclasses in corresponding namespaces.)

Namespaces are not necessarily unique to the Framework Class Library; you can also create yourown namespaces by using the Namespace statement at the beginning of a code file.

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

VB.NET Topics