c# - 从 app.config 文件中检索设置的名称

标签 c# .net c#-4.0 settings

我需要从 app.config 文件中检索 key 设置的名称。

例如:

我的 app.config 文件:

<setting name="IGNORE_CASE" serializeAs="String">
    <value>False</value>
</setting>

我知道我可以使用以下方法检索值:

Properties.Settings.Default.IGNORE_CASE

有没有办法从我的键设置中获取字符串“IGNORE_CASE”?

最佳答案

示例代码here展示了如何遍历所有设置以读取它们的键和值。

为方便起见摘录:

// Get the AppSettings section.        
// This function uses the AppSettings property
// to read the appSettings configuration 
// section.
public static void ReadAppSettings()
{
    // Get the AppSettings section.
    NameValueCollection appSettings =
       ConfigurationManager.AppSettings;

    // Get the AppSettings section elements.
    for (int i = 0; i < appSettings.Count; i++)
    {
      Console.WriteLine("#{0} Key: {1} Value: {2}",
        i, appSettings.GetKey(i), appSettings[i]);
    }
}

关于c# - 从 app.config 文件中检索设置的名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7876733/

相关文章:

c# - WPF 工具包 - IntegerUpDown

c# - 模型中的 Mvvm 嵌套属性已更改

C# SqlDataReader = 空?

c# - Silverlight:如何使用 System.Net.WebClient 忽略(缺少)crossdomain.xml?

.net - 如何在 WinForms 应用程序中安全地存储连接字符串?

c# - ObjectDataSource 找不到非泛型方法

c# - 如何自定义 ".NET FrameworkInitialization Error"?

c# - 如何找到两个图像之间的差异矩形

.net - Prism 。使用 RegisterInstance 执行任务

c# - 只去掉字符串中最左边的字母,只去掉左边的字母