Public (Visual Basic)
Updated: July 20, 2015
For the latest documentation on Visual Studio 2017 RC, see Visual Studio 2017 RC Documentation.
Specifies that one or more declared programming elements have no access restrictions.
If you are publishing a component or set of components, such as a class library, you usually want the programming elements to be accessible by any code that interoperates with your assembly. To confer such unlimited access on an element, you can declare it with
Public access is the normal level for a programming element when you do not need to limit access to it. Note that the access level of an element declared within an interface, module, class, or structure defaults to
Public if you do not declare it otherwise.
- Declaration Context. You can use
Publiconly at module, interface, or namespace level. This means the declaration context for a
Publicelement must be a source file, namespace, interface, module, class, or structure, and cannot be a procedure.
Access Level. All code that can access a module, class, or structure can access its
Default Access. Local variables inside a procedure default to public access, and you cannot use any access modifiers on them.
Access Modifiers. The keywords that specify access level are called access modifiers. For a comparison of the access modifiers, see Access Levels in Visual Basic.
Public modifier can be used in these contexts: