Hi
What is the difference between const and readonly in C#.Net?
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.
Santhosh Kumar JayaramanPosted Jul 20, 2012, 6:27 AM
- Can't be static.
- Value is evaluated at compile time.
- Initiailized at declaration only.
'readonly':VulpesPosted Jul 20, 2012, 6:27 AM
In contrast, the 'readonly' modifier can only be applied to a static or instance field - it can't be applied to a local variable. Also, it can only be given a value either where it's defined or within the enclosing type's constructor and cannot be changed after that. However, it's value is not determined until runtime and can therefore be of any type, not just the built-in types.