Using (Imports) Statics

The using statement (Imports in VB) allows developers to declare namespaces that are in scope; thus, classes in the namespace do not need to be fully qualified inside your code. (See “Organizing Your Code with Namespaces” later in this chapter.) You can now use the same statement with static classes. To do so, in C# you must include the static keyword as in “using static.” In Visual Basic, you simply use Imports and then specific the static library.

The ability to indicate using (Imports in VB) with a static class tells the compiler that the class and its members are now in scope. This allows you to call a method of the static class without referencing the namespace or even the class name inside your code.

As an example, ...

Get Microsoft Visual Studio 2015 Unleashed, Third Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.