Write values in app.config file

后端 未结 10 992
生来不讨喜
生来不讨喜 2020-11-29 01:46

can anyone please help me how can I set/store values in the app.config file using c#, is it possible at all?

10条回答
  •  日久生厌
    2020-11-29 02:02

    //if you want change
    Configuration config = ConfigurationManager.OpenExeConfiguration(Application.ExecutablePath);
    config.AppSettings.Settings[key].Value = value;
    
    //if you want add
    Configuration config = ConfigurationManager.OpenExeConfiguration(Application.ExecutablePath);
    config.AppSettings.Settings.Add("key", value);
    

提交回复
热议问题