Working with Block-Level Scope

Scope relates to opportunity for use. When a name is in scope, you can use it; when a name is not in scope, you cannot use it.

There are several layers of scope in Visual Basic .NET. From the broadest to narrowest scope, there is namespace, type (applies equally to class, module, and structure), procedure, and block scope. Things declared in a broader scope are accessible to narrower, subordinate scopes directly. For example, a private class field is accessible to a procedure in the same class and will not cause a name conflict with a field with the same name in another class.

Additionally, narrower-scoped names are accessible to other areas of code using the member-of operator (.). For example, the ToString method ...

Get Visual Basic® .NET 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.