New course! Every coder should learn Generative AI!
Try a free lesson0
"The readonly Modifier", Which statements are true?
1. readonly fields can be initialized only when declared. 2. readonly fields can be initialized by the constructor. 3. constants should be assigned a value when declared. 4. constants can be initialized by the constructors. I am stuck on this question. plz help me guys..
1 Answer
+ 1
Option 2 and 3 are correct
Constants must be initialized like
const string str = "Hello World";
readonly fields can be initialized with the conrructor but does not have to be initialized when declared