I have a aspx usercontrol with
static readonly string foo = GetFromDB();
now I am wondering what the lifetime of foo is. When does foo get it’s value. Everytime the usercontrol instance is created or only once? The reason for wanting to know is that GetFromDB might return a different value over time. If foo has the same value for a while thats fine. If it never changes untill the app domain is recreated then that isn’t.
When you first access the containing class and guaranteed to be executed only once and it will remain the same for the entire life of the AppDomain. You may check the following article on MSDN about static field initialization: