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
orFor
)
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
Phản hồi
https://aka.ms/ContentUserFeedback.
Sắp ra mắt: Trong năm 2024, chúng tôi sẽ dần gỡ bỏ Sự cố với GitHub dưới dạng cơ chế phản hồi cho nội dung và thay thế bằng hệ thống phản hồi mới. Để biết thêm thông tin, hãy xem:Gửi và xem ý kiến phản hồi dành cho