I am trying to do this below, is there a way to do this or are web.configs only available at run-time, because I am getting a red line error saying must be compile time constant?
AppSettings:
<add key="MyString" value="TheValueOfTheString"/>
Code:
public const string MyString = ConfigurationManager.AppSettings["MyString"];
the problem is the use of const. const means the value is hard coded at design time.
an appsettings value is not known until runtime so it’s not a constant value. instead you can use a static readonly value
the difference is how the value is interpereted at compile time. when a constant is used the actual value is referenced, not the variable
MyString. astatic readonlyvalue is compiled as the variable.