【问题标题】:What does ConfigurationManager.AppSettings do?ConfigurationManager.AppSettings 有什么作用?
【发布时间】:2015-05-29 03:07:05
【问题描述】:

我目前的理解是它调用我的配置文件中的某些内容并返回数据。我不清楚 ConfigurationManager.AppSettings 的参数是什么。

我已经浏览过这个文档 (https://msdn.microsoft.com/en-us/library/1xtk877y%28v=vs.110%29.aspx) 但不太明白。

对于上下文,这是我正在使用的代码:

    string code1 = ConfigurationManager.AppSettings[string1 + string2];
    string code2 = ConfigurationManager.AppSettings[string3];
    string query = new BuildMDXQuery(cube).BuildFetchInventoryQuery(code1, code2);

我想知道如何找到在我的配置文件中调用的内容(如果有的话),以及使用 ConfigurationManager.AppSettings 的目的是什么。谢谢!

【问题讨论】:

    标签: c# configurationmanager


    【解决方案1】:

    它从配置文件的 appSettings 部分读取,所以...

    Configuration.AppSettings["Whatever"]
    

    ...在以下情况下会返回“Blah”:

    <configuration>
        <appSettings>
            <add key="Whatever" value="Blah" />
        </appSettings>
    </configuration>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-07-08
      • 2010-12-27
      • 2011-10-27
      • 2019-12-07
      • 2010-09-28
      • 1970-01-01
      • 2023-04-10
      • 2011-07-17
      相关资源
      最近更新 更多