Modifiers are C# keywords used to modify declarations of types and type members.
types - classes, structs, interfaces, enum
type members - field, properties, methods, indexers
|abstract||Indicates 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
|extern||Indicates that a method is implemented externally|
|internal||Indicates 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.
|new||Replaces 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
|override||Indicates that the method is a new implementation for a base class virtual member.|
In VB.Net this is Overrides
|public||Indicates 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.
|private||Indicates 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.
|protected||Indicates the member can be accessed only by code inside the class or struct OR in a class derived from that class.|
|protected internal||Indicates 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.
|readonly||Can only be assigned a value in the declaration or in the constructor|
|sealed||Indicates 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
|static||Indicates 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
|unsafe||Required for any operation involving pointers|
|virtual||A 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
|volatile||Can be modified by something else, eg hardware or a concurrent thread|
© 2022 Better Solutions Limited. All Rights Reserved. © 2022 Better Solutions Limited TopPrevNext