What is Difference Between constant and readonly.
Ans:
Ans:
const
- They can not be declared as
static
(they are implicitly static) - The value of constant is evaluated at compile time
- constants are initialized at declaration only
readonly
- They can be either instance-level or static
- The value is evaluated at run time
- readonly can be initialized in declaration or by code in the constructor
imp
const
: Can't be changed anywhere.readonly
: This value can only be changed in the constructor. Can't be changed in normal functions
No comments:
Post a Comment