They aren't the same.
A
const
value is defined at compile time and can never be changed.
A
readonly
value is not defined at compile time - it is set only in the appropriate class constructor and can be a different value each time the code is run. Once set, the rest of the code cannot change the value, so it's a "settable constant" which allows you to (for example) read a value from a database instead of defining it at compile time, and treat it as a constant from there on.
Quote:
I can't understand about readonly
Think about it: pi is a constant - 3.1415927.... it is the same value for every calculation you make, regardless of where in the universe you try to apply it.
So is your date of birth - it never changes for your entire lifetime. But ... your birthday is not the same as mine, which also never changes.
pi is a
const
value: you define it at compile time and it never changes.
But "dateOfBirth" is different, you can't change it, but it is fixed for each person: it's
readonly
because you define the actual value when you create an instance of a person, and can never change it again.
So a
const
value is fixed from the moment you compile your application, and to change it you must recompile; while a
readonly
value is fixed only when the app runs and sets the value in the class constructor.
Does that make sense?