C# 读取 config 文件
ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap();
fileMap.ExeConfigFilename = filePath;
Configuration config = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
AppSettingsSection appSettings = (AppSettingsSection)config.GetSection("appSettings");
KeyValueConfigurationCollection keyValues = appSettings.Settings;
Dictionary<string, string> items = new Dictionary<string, string>();
foreach (string key in keyValues.AllKeys)
{
items.Add(key, keyValues[key].Value);
}
return items;
注意 : 不要使用 var 对上面程序进行 变量声明
积少成多 共享 交流 进步