As soon as I started programming C# (ASP.NET) I was surprised at how restrictive constants were. So far, I haven’t used them much and I feel I missed the concept. How would you guys make use of constants in a typical ASP.NET application?
How would declare a constant struct such as System.Drawing.Color?
Would you guys use readonly when const cannot be used?
I would like to find out how people are using const and readonly and to discuss alternatives if any.
Constants are for defining things in your program that should not change, but need to be referenced multiple times.
Now if you want to change SLEEP_TIME you can do it in one place.
As for a constant struct I’d usually use an enum
Readonly is useful for references that need to be assigned once
And if you need to change something (ie: initialize something to null, then change it), it by definition can’t be const.