The configuration file content is as follows:
XML Version = "1.0" encoding = "UTF-8"?>
sectiongroup>
configsections>
mysection>
myDictionarysection>
mysection1>
mysection2>
mysections>
appsettings>
configure>
The code segment 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 "]);
Console.writeline ("DictionarySECTIONVALUE2: DIC [" DictionarySECTIONKEY2 "]);
Console.writeline ("DictionarySECTIONVALUE3:" DIC ["DictionarySECTIONKEY3"]);
Console.writeLine ();
}
Private static void testsectiongroup ()
{
Console.WriteLine ("TestSECTIONGROUP ...");
NameValueCollection config1;
NameValueCollection config2;
Config1 = (NameValueCollection) configurationSettings.getConfig ("Mysections / MySECTION1");
Config2 = (NameValueCollection) ConfigurationSettings.getConfig ("Mysections / MySECTION2");
Console.writeline ("Mysections / Mysections1 / Value1:" Config1 ["MySECTION1_KEY1"]);
Console.writeline ("Mysections / Mysections1 / Value2:" Config1 ["MySECTION1_KEY2"]);
Console.writeline ("Mysections / Mysections2 / Value1:" Config2 ["MySECTION2_KEY1"]);
Console.writeline ("Mysections / Mysections2 / Value2:" Config2 ["MySECTION2_KEY2"]);
Console.writeLine ();
}