I am trying to get all the keys and values of config file's app settings in a page constructor so I can use them in the page. I tried Linq but I am not sure how to get values along with keys in a simple manner. right now I got all keys and then using foreach to get all values and I am sure that is not a smart way. Please advice..
string[] repositoryUrls = ConfigurationManager.AppSettings.AllKeys
.Select(key => ConfigurationManager.AppSettings[key])
.ToArray();
Thanks
It sounds like you actually want a dictionary of Key names and Value values instead of a string array.
var dict =
ConfigurationManager.AppSettings.AllKeys
.ToDictionary(k => k, v => ConfigurationManager.AppSettings[v]);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With