Access Modifiers

Modifiers are C# keywords used to modify declarations of types and type members.
types - classes, structs, interfaces, enum
type members - field, properties, methods, indexers


ModifierDescription
abstractIndicates that a class is just a base class.
Indicates that a method must have a new implementation in a derived class
In VB.Net this is MustInherit | MustOverride
const 
externIndicates that a method is implemented externally
internalIndicates the member can be accessed by any code in the same assembly but not from other assemblies.
In C# this is the default for classes and structures.
In VB.Net this is the default for classes, structures, interfaces, delegates, enumerations and modules.
In VB.Net this is Friend.
newReplaces the member in the base class.
When a member of a derived class has the same name as its base class then the derived class instance replaces that in the base class.
In C# this is the default for any members with the same name but using this modifier will remove the automatic warning.
In VB.Net this is Shadows
overrideIndicates that the method is a new implementation for a base class virtual member.
In VB.Net this is Overrides
partial 
publicIndicates the member can be accessed by any code in the same assembly or another assembly that references it. There are no restrictions.
It is completely visible.
Can be called from outside that class and from other assemblies.
In C# this is the default for namespaces, interfaces and enumerations.
In VB.Net this is the default for methods.
privateIndicates the member can only be accessed by code inside the class or struct.
It is good practice to keep all fields private.
In C# this is the default for (nested) classes and structures.
protectedIndicates the member can be accessed only by code inside the class or struct OR in a class derived from that class.
protected internalIndicates the method can be accessed by any code in the same assembly OR from within a derived class in another assembly.
Using 'internal protected' will also work but is never used.
readonlyCan only be assigned a value in the declaration or in the constructor
sealedIndicates that a class cannot be inherited.
Indicates that a method cannot have a new implementation in a derived class (cannot be overridden)
In VB.Net this is NotInheritable | NotOverridable
staticIndicates that a member belongs to the type itself and does not require an instance of the object
A class can provide a container for methods that do not have to modify any internal instance fields or properties.
A static class is the same as having only static members and a private constructor
A static class is also a sealed class.
In VB.Net this is Shared
unsafeRequired for any operation involving pointers
virtualA method may be overridden.
A class can be overridden in a derived class.
A method can be modified by the operating system, the hardware or a concurrently executing thread.
In VB.Net this is Overrideable
volatileCan be modified by something else, eg hardware or a concurrent thread


© 2018 Better Solutions Limited. All Rights Reserved. © 2018 Better Solutions Limited TopPrevNext