Previous Topic Next topic Print topic


Access Modifiers

The access modifiers of an item control the visibility (accessibility) of the item to other code. For example, you can call public methods from anywhere, whereas private methods can be called only from other methods within the same type.

access-modifier

Further Information

By default, all types and members are PUBLIC, with the exception of fields which are PRIVATE.

The modifier affects the visibility of an item as follows:

Modifier: Item is visible:
PUBLIC always
PRIVATE when the calling type is the same as the target type
PROTECTED when the calling type inherits from the target type.
INTERNAL when the calling type is in the same assembly as the target
PROTECTED INTERNAL or INTERNAL PROTECTED when the calling type derives from the target type, or the calling type is in the same assembly as the target
PUBLIC
Indicates that this item may be accessed from any code.
PRIVATE
Indicates that this item may be accessed only from within the containing type.
PROTECTED
Indicates that this item may be accessed only from within the containing type or from a subtype that inherits from the containing type. You cannot specify PROTECTED on an abstract member. PROTECTED restricts access within an inheritance tree. For example, a protected field in a superclass can be accessed from any subclass, but it can't be accessed from a class outside the inheritance tree.
INTERNAL
Indicates that this item may be accessed only from within the current compilation unit.
PROTECTED INTERNAL or INTERNAL PROTECTED
Indicates that this item may be accessed only from within the containing type, from a subtype that inherits from the containing type, or from within the current compilation unit.
Previous Topic Next topic Print topic