在C#中,可以使用System.Configuration命名空间中的ConfigurationManager类来读取和修改配置文件。以下是一个简单的示例代码:
string value = ConfigurationManager.AppSettings["keyName"];Console.WriteLine("Value: " + value);修改配置文件中的值:Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);config.AppSettings.Settings["keyName"].Value = "newValue";config.Save(ConfigurationSaveMode.Modified);ConfigurationManager.RefreshSection("appSettings");在以上示例中,keyName是配置文件中的键,可以根据需要进行修改。记得在修改配置文件后调用Save方法和RefreshSection方法来保存和刷新配置文件。


