What's difference between readonly and const ?
Thanks :-)
Another difference !!!
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
ShankeyRank #972 · 2.1K reputationPosted Aug 12, 2010, 9:05 PM EDT
Following are the important points which can be prove as a difference and will help to decide whether to use Const / Readonly field:
- 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.
- A readonly fields can have different values depending on the constructor used.
- A const field is a compile-time constant.
- A readonly field can be used for runtime constants.
Please mark my answer as accepted if it clears your doubt. :)Majid KamaliRank #6,453 · 266 reputationPosted Aug 13, 2010, 3:15 AM EDT