Classes and Objects
- slide 18 : 29
Constant and readonly variables
Constants and readonly variables cannot be changed during program execution
Constants
declared with use of the
const
keyword
Computed at compile-time
Must be initialized by an initializer
The initializer is evaluated at compile time
No memory is allocated to constants
Must be of a simple type, a string, or a reference type
Readonly variables
declared with use of the
readonly
modifier
Computed at object-creation time
Must either be initialized by an initializer or in a constructor
Cannot be modified in other parts of the program
Legal use of constants and readonly variables.
Illegal use of constant and readonly variables.