Skip to content

Latest commit

 

History

History
60 lines (51 loc) · 4.2 KB

File metadata and controls

60 lines (51 loc) · 4.2 KB
title Declaration Contexts and Default Access Levels (Visual Basic)
ms.date 07/20/2015
ms.prod .net
ms.reviewer
ms.suite
ms.technology
devlang-visual-basic
ms.topic article
helpviewer_keywords
module level, defined
declaration contexts, Visual Basic
procedure level, defined
namespace level, defined
access levels, Visual Basic
access levels, default levels
ms.assetid bf63b96e-e825-4745-88c8-5dae222728db
caps.latest.revision 8
author dotnet-bot
ms.author dotnetcontent

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

Friend
Private
Public