我需要从 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/