Adding and reading from a Config file

后端 未结 3 1392
执念已碎
执念已碎 2020-12-04 10:40

I have created a C# console based project. In that project i have some variables like companyName, companyType which are Strings.

3条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-04 10:58

    Configuration configManager = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
    KeyValueConfigurationCollection confCollection = configManager.AppSettings.Settings;
    
    confCollection["YourKey"].Value = "YourNewKey";
    
    
    configManager.Save(ConfigurationSaveMode.Modified);
    ConfigurationManager.RefreshSection(configManager.AppSettings.SectionInformation.Name);
    

提交回复
热议问题