I would like to use ConfigurationManager
to access some string values from a static class. However, I need to handle specifically the absence of a valu
static constructors are fine, the great thing about them is that they are guaranteed by the runtime to be executed once and once only - the first time the class is used in any circumstance.
You could alternatively use the coalesce operator (??
) to set a default value:
private static readonly string someStr = ConfigurationManager.AppSettings["abc"] ?? "some default value";