posted 9/30/2010 by Vivek Thakur
If in your C# class you want to use a variable whose value will not change during the lifetime of that class, then you have two options:
1. Use the "const" keyword: for e.g. public const int myVar = 100;
2. Use the "static readonly" keyword: for e.g. public static readonly int myVar = ConfigurationManager.AppSettings["value"];
The const variable has a limitation: it can ONLY be set during compile time. This means you cannot set its value using any code logic, like getting its value from some config file, or from some "if" condition. Whereas the value of a static readonly field can be set at run time, and can thus be modified by the containing class using any custom logic.
In the static readonly case, the containing class is allowed to modify it only
What kind of email newsletter would you prefer to receive from CodeAsp.Net?18