In C#, modifier keywords are used to modify the behavior and accessibility of classes, methods, fields, properties, and other elements in the C# code. Here's a brief description of each modifier keyword:
Keyword | Description |
---|---|
abstract | Indicates that a class or method has no implementation and must be subclassed or overridden. |
async | Specifies that a method is asynchronous and can use the "await" keyword to wait for asynchronous operations. |
const | Declares a constant value that cannot be changed after initialization. |
event | Defines and handles events that allow communication between objects in an event-driven programming model. |
extern | Declares a method that is implemented externally, often used with Platform Invoke (P/Invoke) to call unmanaged code. |
new | Hides a method with the same name in a base class when creating a method with the same name in a derived class. |
override | Indicates that a method, property, or indexer in a derived class overrides a virtual or abstract member in a base class. |
partial | Enables the definition of a class or method to be split into multiple files within the same namespace. |
readonly | Defines a read-only field or variable whose value can only be set during object initialization or in the constructor. |
sealed | Prevents a class from being used as a base class, making it a terminal class that cannot be further derived. |
static | Indicates that a member (field, property, method, or nested class) belongs to the type itself, not individual instances. |
unsafe | Marks a block of code containing unsafe or unmanaged code, which requires special permissions and bypasses safety features. |
virtual | Specifies that a method, property, or indexer in a base class can be overridden in derived classes. |
volatile | Indicates that a field can be changed by multiple threads and should not be optimized or cached by the compiler or hardware. |