One: The method of accessing value via key:
Determine if there is a key (non-null) if (ConfigurationManager.AppSettings.HasKeys ()) { //get "thedate" in the App. config configuration file The value of the key, foreach (string s in ConfigurationManager.AppSettings.GetValues ("Thedate")) { Console.WriteLine (s); } }
Two get all K EY's value Collection
Determine if there is a key (not null) in the App. config configuration file (ConfigurationManager.AppSettings.HasKeys ()) {Li st<string> Thekeys = new list<string> (); Save the collection of keys list<string> thevalues = new list<string> (); Save the collection of value//traverse out all keys and add the Thekeys collection to foreach (String Thekey in Configurationmanager.appsett Ings. Keys) {thekeys.add (Thekey); }//Walk out all value according to key and add the Thevalues set for (int i = 0; i < Thekeys.count; i++) {foreach (String thevalue in ConfigurationManager.AppSettings.GetValues (Thekeys[i])) {Thevalues.add (thevalue); }}//Verify the Console.WriteLine ("*************key*************"); foreach (string s in Thekeys) {Console.WriteLine (s); } Console.WriteLine ("************value************"); foreach (var item in thevalues) {Console.WriteLine (item); } }
C # Reading and writing config profile-read configuration file class