C # Read and write config profile-reads the configuration file class

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.