Constant & ReadOnly
Difference between Constant & Read only: by Sagar Jaybhay
Constant – are compile-time constant and not assign a static keyword to constant and also accessible in static method.
Value is set when the declaration performed means at the time declaration you can’t declare blank or null and then assign value is not possible.
When to use?
- Data is absolutely constant then and then you can use constantly when values are absolutely constant.
Read-only- Is runtime constant means value is assigned at run time in the constructor only you can’t be assigned value in the methods.
- When you want to decide at first runtime and then through-out the program it remains constant.
- After the first time initialization, you can’t change value.