Reading keyvalue pairs into dictionary from app.config configSection

using ConfigurationManager class you can get whole section from app.config file as Hashtable which you can convert to Dictionary if you want to:

var section = (ConfigurationManager.GetSection("DeviceSettings/MajorCommands") as System.Collections.Hashtable)
                 .Cast<System.Collections.DictionaryEntry>()
                 .ToDictionary(n=>n.Key.ToString(), n=>n.Value.ToString());

you’ll need to add reference to System.Configuration assembly

Leave a Comment