【问题标题】:What is the role of AppSettingsReader in MSDN example?AppSettingsReader 在 MSDN 示例中的作用是什么?
【发布时间】:2015-02-07 08:20:35
【问题描述】:

我正在阅读 MSDN 页面 AppSettingsReader.GetValue 以了解更多信息。有一个例子,我无法弄清楚AppSettingsReader在其中的作用。谁能告诉我那里发生了什么。

MSDN 示例:

static void DisplayAppSettings()
{

    try
    {

        AppSettingsReader reader = new AppSettingsReader();


        NameValueCollection appSettings = ConfigurationManager.AppSettings;

        for (int i = 0; i < appSettings.Count; i++)
        {
            Console.WriteLine("Key : {0} Value: {1}",
              appSettings.GetKey(i), appSettings[i]);
        }

    }
    catch (ConfigurationErrorsException e)
    {
        Console.WriteLine("[DisplayAppSettings: {0}]", e.ToString());
    }

}

【问题讨论】:

    标签: c# .net msdn


    【解决方案1】:

    示例代码实例化了一个AppSettingsReader 对象,但对它什么也不做。您可以删除该行,不会有任何改变。

    【讨论】:

      【解决方案2】:

      在此特定示例中,AppSettingsReader 是未使用的变量。 AppSettingsReader 用于从配置文件中读取应用设置。您可以在 MSDN page 上找到一个示例

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-11-24
        • 2013-05-23
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多