Imports Directives
As we saw before, namespaces can expose objects that expose members. Moreover, namespaces can expose nested namespaces, exposing objects and so on. You often need to access members of objects exposed by nested namespaces. To avoid the need of typing the entire name of long (or nested) namespaces and writing long lines of code, the Visual Basic language offers the Imports
directive. For example, consider the following lines of code that open a file on disk:
The FileStream
class is exposed by the IO
namespace that is exposed by the System
namespace. You could place the following directive at the beginning of the code:
Imports ...
Get Visual Basic® 2010 Unleashed now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.