Readonly indicates read-only, and const indicates constant
I. They are used to identify constants.
2. const must be assigned a value while being declared;
Readonly can be assigned a value during initialization. Therefore, the readonly field may have different values based on the constructors used.
3. the const field is the compile time, And the readonly field can be used to run the time.
1. const requires that a definite value be calculated during compilation to replace every place that calls this constant. Therefore, the value cannot be extracted from the variable to initialize the constant.
2. readonly is executed during computation and is determined only at runtime.
4. By default, const is static. If readonly is set to static, it must be explicitly declared.
5. The reference type modified by const can only be string or other reference types whose values are null.
6. Objects, arrays, and struct cannot be declared as const constants.
7. readonly can only be used to modify the field of a class. It cannot modify local variables or other class members such as property.
By: dxh_0829