InterviewSolution
| 1. |
Whats The Difference Between Const And Readonly? |
|
Answer» The readonly KEYWORD is different from the CONST keyword. A const field can only be INITIALIZED at the declaration of the field. A readonly field can be initialized either at the declaration or in a constructor. Therefore, readonly fields can have different VALUES depending on the constructor used. Also, while a const field is a compile-time constant, the readonly field can be used for runtirne constants as in the following example: public static readonly uint [] = (uint) DateTime,Now.Ticks; The readonly keyword is different from the const keyword. A const field can only be initialized at the declaration of the field. A readonly field can be initialized either at the declaration or in a constructor. Therefore, readonly fields can have different values depending on the constructor used. Also, while a const field is a compile-time constant, the readonly field can be used for runtirne constants as in the following example: public static readonly uint [] = (uint) DateTime,Now.Ticks; |
|