Skip to content

Latest commit

 

History

History
55 lines (43 loc) · 3.23 KB

declaration-contexts-and-default-access-levels.md

File metadata and controls

55 lines (43 loc) · 3.23 KB
description title ms.date helpviewer_keywords ms.assetid
Learn more about: Declaration Contexts and Default Access Levels (Visual Basic)
Declaration Contexts and Default Access Levels
07/20/2015
module level, defined
declaration contexts, Visual Basic
procedure level, defined
namespace level, defined
access levels, Visual Basic
access levels, default levels
bf63b96e-e825-4745-88c8-5dae222728db

Declaration Contexts and Default Access Levels (Visual Basic)

This topic describes which Visual Basic types can be declared within which other types, and what their access levels default to if not specified.

Declaration Context Levels

The declaration context of a programming element is the region of code in which it is declared. This is often another programming element, which is then called the containing element.

The levels for declaration contexts are the following:

  • Namespace level — within a source file or namespace but not within a class, structure, module, or interface

  • Module level — within a class, structure, module, or interface but not within a procedure or block

  • Procedure level — within a procedure or block (such as If or For)

The following table shows the default access levels for various declared programming elements, depending on their declaration contexts.

Declared element Namespace level Module level Procedure level
Variable (Dim Statement) Not allowed Private (Public in Structure, not allowed in Interface) Public
Constant (Const Statement) Not allowed Private (Public in Structure, not allowed in Interface) Public
Enumeration (Enum Statement) Friend Public Not allowed
Class (Class Statement) Friend Public Not allowed
Structure (Structure Statement) Friend Public Not allowed
Module (Module Statement) Friend Not allowed Not allowed
Interface (Interface Statement) Friend Public Not allowed
Procedure (Function Statement, Sub Statement) Not allowed Public Not allowed
External reference (Declare Statement) Not allowed Public (not allowed in Interface) Not allowed
Operator (Operator Statement) Not allowed Public (not allowed in Interface or Module) Not allowed
Property (Property Statement) Not allowed Public Not allowed
Default property (Default) Not allowed Public (not allowed in Module) Not allowed
Event (Event Statement) Not allowed Public Not allowed
Delegate (Delegate Statement) Friend Public Not allowed

For more information, see Access levels in Visual Basic.

See also