以下是app.config或web.config的定义,定义了一个参数,键为isinit,值为false
以下是读和写config文件的方法定义:
写入:
internal void settingApp_write(string key, string val) { System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); config.AppSettings.Settings["IsInit"].Value = val; config.Save(ConfigurationSaveMode.Modified); ConfigurationManager.RefreshSection("appSettings"); }
读取:
internal string settingApp_read(string key) { var val = ConfigurationManager.AppSettings[key]; return val; }
使用方法:
写入测试:
settingApp_write("IsInit","true");
取出测试:
var setting = settingApp_read("Isinit");
此级别的修改是项目级别的config文件修改,也就是你最终程序Bin目录下的那个config文件的操作。
更多C#操作config文件的具体方法相关文章请关注PHP中文网!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号