. NET configuration file Common configuration description

Source: Internet
Author: User

<?xml:namespace prefix = o ns = "Urn:schemas-microsoft-com:office:office"/>

The contents of the configuration file are as follows:

<?xml version= "1.0" encoding= "Utf-8"?>

<configuration>

<configSections>

<section name= "MySection" type= "System.Configuration.NameValueSectionHandler"/>

<section name= "mysingletagsection" type= "System.Configuration.SingleTagSectionHandler"/>

<section name= "mydictionarysection" type= "System.Configuration.DictionarySectionHandler"/>

<sectiongroup name= "Mysections" >

<section name= "MySection1" type= "System.Configuration.NameValueSectionHandler"/>

<section name= "MySection2" type= "System.Configuration.NameValueSectionHandler"/>

</sectionGroup>

</configSections>

<mySection>

<add key= "Key1" value= "value1"/>

<add key= "Key2" value= "value2"/>

</mySection>

<mysingletagsection setting1= "value1" setting2= "value2" setting3= "Value3"/>

<myDictionarySection>

<add key= "DictionarySectionKey1" value= "DictionarySectionValue1"/>

<add key= "DictionarySectionKey2" value= "DictionarySectionValue2"/>

<add key= "DictionarySectionKey3" value= "DictionarySectionValue3"/>

</myDictionarySection>

<mySections>

<mySection1>

<add key= "Mysection1_key1" value= "mysection1_value1"/>

<add key= "Mysection1_key2" value= "Mysection1_value2"/>

</mySection1>

<mySection2>

<add key= "Mysection2_key1" value= "mysection2_value1"/>

<add key= "Mysection2_key2" value= "Mysection2_value2"/>

</mySection2>

</mySections>

<appSettings>

<add key= "Appkey1" value= "appvalue1"/>

<add key= "Appkey2" value= "Appvalue2"/>

</appSettings>

</configuration>

The code snippet is as follows:

private static void Testappsettings ()

{

Console.WriteLine ("Testappsettings ...");

NameValueCollection config = configurationsettings.appsettings;

Console.WriteLine ("Value1:" + config["Key1"]);

Console.WriteLine ("value2:" + config["Key2"]);

Console.WriteLine ();

}

private static void Testsection ()

{

Console.WriteLine ("Testsection ...");

NameValueCollection config;

Config = (NameValueCollection) configurationsettings.getconfig ("MySection");

Console.WriteLine ("Value1:" + config["Key1"]);

Console.WriteLine ("value2:" + config["Key2"]);

Console.WriteLine ();

}

private static void Testsingletagsection ()

{

Console.WriteLine ("Testsingletagsection ...");

IDictionary dic;

DIC = (IDictionary) configurationsettings.getconfig ("Mysingletagsection");

Console.WriteLine ("Value1:" + dic["setting1"]);

Console.WriteLine ("value2:" + dic["setting2"]);

Console.WriteLine ("Value3:" + dic["Setting3"]);

Console.WriteLine ();

}

private static void Testdictionarysection ()

{

Console.WriteLine ("Testdictionarysection ...");

IDictionary dic;

DIC = (IDictionary) configurationsettings.getconfig ("Mydictionarysection");

Console.WriteLine ("DictionarySectionValue1:" + dic["DictionarySectionKey1"]);

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.