获取App.Config中自定义的配置节点的信息

C#代码

ExpandedBlockStart.gif View Code
 1  static  void GetConfigInfo()
 2 {
 3      // 访问Test1
 4       // IDictionary idTest1 = (IDictionary)ConfigurationSettings.GetConfig("Test1");
 5      IDictionary idTest1 = (IDictionary)System.Configuration.ConfigurationManager.GetSection( " Test1 ");
 6      string str = ( string)idTest1[ " setting1 "] +  " _____ " + ( string)idTest1[ " setting2 "];
 7     Console.WriteLine(str);
 8 
 9      // 访问配置节 Test2
10      IDictionary idTest2 = (IDictionary)System.Configuration.ConfigurationManager.GetSection( " Test2 ");            
11      string[] keys =  new  string[idTest2.Keys.Count];
12      string[] values =  new  string[idTest2.Keys.Count];
13     idTest2.Keys.CopyTo(keys,  0);
14     idTest2.Values.CopyTo(values,  0);
15     Console.WriteLine(keys[ 0] +  " _______________ " + values[ 0]);
16 }

 

配置文件信息

ExpandedBlockStart.gif View Code
<? xml version="1.0" encoding="utf-8"  ?>
< configuration >
   < configSections >
     <!-- 声明一个配置节,它的名字叫Test1,类型为...再设置配置节部分使用 <Test1 setting1= "Hello" setting2="World"/>它的第一个设置的值是Hello,第二个值是World,当然还可以更多 -->
     < section  name  = "Test1"  type ="System.Configuration.SingleTagSectionHandler" />
     < section  name  = "Test2"  type  ="System.Configuration.DictionarySectionHandler" />
     < section  name  = "Test3"  type ="System.Configuration.NameValueSectionHandler"   />
   </ configSections >

   < Test1  setting1 ="Hello"  setting2  ="World" >
   </ Test1 >
   < Test2 >
     < add  key  ="Hello1"  value  ="World" ></ add >
     < add  key  ="Hello2"  value  ="World" ></ add >
     < add  key  ="Hello3"  value  ="World" ></ add >
     < add  key  ="Hello4"  value  ="World" ></ add >
   </ Test2 >
   < Test3 >
     < add  key ="Hello"  value  ="World" ></ add >
   </ Test3 >
  
   < appSettings >
     < add  key ="No1"  value ="GoldBuilder" />
     < add  key ="No2"  value ="NormalBuilder" />
   </ appSettings >


</ configuration >

 

 

转载于:https://www.cnblogs.com/pnljs/archive/2013/04/24/3039908.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值