What's difference between readonly and const ?
Thanks :-)
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
ShankeyPosted Aug 13, 2010, 1:05 AM
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 KamaliPosted Aug 13, 2010, 7:15 AM