CSharp examples for Custom Type:Field
A field is a variable that is a member of a class or struct. For example:
class Animal { string name; public int Age = 10; }
Fields allow the following modifiers:
Static modifier | static |
---|---|
Access modifiers | public internal private protected |
Inheritance modifier | new |
Unsafe code modifier | unsafe |
Read-only modifier | readonly |
Threading modifier | volatile |
The readonly modifier prevents a field from being modified after construction.
A read-only field can be assigned only in its declaration or within the enclosing type's constructor.