从App.Config文件(C#)获取自定义设置 [英] getting custom settings from App.Config file (C#)

查看:273
本文介绍了从App.Config文件(C#)获取自定义设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个自定义配置文件,如下所示:

I've created a custom config file that looks like this:

  <ConnectionSettings>
    <Connections>
       <Connection name="ConnectionA">
         <Environments>
           <Environment name="test1" />
           <Environment name="test2" />
           <Environment name="test3" />
         </Environments>
       </Connection> 
     </Connections>
  </ConnectionSettings>


我可以通过以下方式访问我的数据:

I can access my data doing this:

string name = TradeConfig.Settings.Connections[0].Name.ToString();

string env = TradeConfig.Settings.Connections[0].Environments[0].Name.ToString();

我的问题是,可以使用关键字而不是使用索引访问数据吗?如:
Connections ["ConnectionA"].Environments ["test1"]

My question is, instead of access the data using indexes, is it possible to use keywords? such as:
Connections["ConnectionA"].Environments["test1"]

代替

连接[0].环境[0]

Connections[0].Environments[0]

推荐答案

凹凸


这篇关于从App.Config文件(C#)获取自定义设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆