Reputation: 5242
I have a app.config looking like this:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<appSettings>
<add key="Setting1" value="value1" />
<add key="Setting2" value="value2" />
</appSettings>
</configuration>
Is it possible to somehow read the whole section of settings? Instead of just calling them one by one:
private static readonly string Setting1 = ConfigurationManager.AppSettings["Setting1"];
private static readonly int Setting2 = ConfigurationManager.AppSettings["Setting2"];
Is that possible? If not by this way, how should I achieve this (was thinking about creating an own Settings.xml but I wanna try this first).
Upvotes: 0
Views: 19
Reputation: 108975
Just directly use the object returned by ConfigurationManager.AppSettings
: it has a whole load of other members.
eg.
var as = ConfigurationManager.AppSettings;
foreach (string k in as.AllKeys) {
Console.WriteLine("{0}: {1}", k, as[k]);
}
Upvotes: 2