扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
<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>
代码片断如下:
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();
}
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者