web.config中不同结点之间的获取异同。(类枚举值)

1.appSettings结点
  1. // Get appSettings.
  2. static void GetAppSettings()
  3. {
  4.     // Get the appSettings.
  5.     NameValueCollection appSettings =
  6.          ConfigurationManager.AppSettings;
  7.     
  8.     // Get the collection enumerator.
  9.     IEnumerator appSettingsEnum =
  10.         appSettings.Keys.GetEnumerator();
  11.     // Loop through the collection and
  12.     // display the appSettings key, value pairs.
  13.     int i = 0;
  14.     Console.WriteLine("App settings.");
  15.     while (appSettingsEnum.MoveNext())
  16.     {
  17.         string key = appSettings.Keys[i];
  18.         Console.WriteLine("Name: {0 Value: {1",
  19.         key, appSettings[key]);
  20.         i += 1;
  21.     
  22.     }

2.connectionStrings结点

  1. // Get connectionStrings.
  2. static void GetConnectionStrings()
  3. {
  4.     // Get the connectionStrings.
  5.     ConnectionStringSettingsCollection connectionStrings =
  6.          ConfigurationManager.ConnectionStrings;
  7.     // Get the collection enumerator.
  8.     IEnumerator connectionStringsEnum =
  9.         connectionStrings.GetEnumerator();
  10.     // Loop through the collection and 
  11.     // display the connectionStrings key, value pairs.
  12.     int i = 0;
  13.     Console.WriteLine("Connection strings.");
  14.     while (connectionStringsEnum.MoveNext())
  15.     {
  16.         string name = connectionStrings[i].Name;
  17.         Console.WriteLine("Name: {0 Value: {1",
  18.         name, connectionStrings[name]);
  19.         i += 1;
  20.      }

 

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值