Read-Only Fields
Read-Only fields
Read-only fields represent object data that is set and never changed for the lifetime of the object.
- A variable in a class, A read-only is a variable defined in a class.
- holds a value that is initialized and then not changed.
- Must be initialized, in the declaration, or in a constructor
- Think of a read-only field as a runtime constant value.
Read-only fields syntax
- Optional accessibility modifier, start with optionally accessibility modifier, in many cases, read-only fields are publicly accessible to the application.
- optional static keyword
- Readonly keyword
- Data type, any data type can be specified.
- Field name, PasclCasing
- Assigned to a value, must be initialized to a value, it can be in the declaration time.
Comments
Post a Comment