c# - 是否可以使用代码将项目添加到 C# 设置

标签 c# settings

我想在我的 C# 应用程序设置中添加一些变量,有什么方法可以用代码来实现。我可以通过项目,然后是 myApp 属性等来做到这一点,但我想在应用程序运行时添加设置,所以我应该通过代码来完成。或者我怎样才能使设置类型成为类似这样的 LinkedList<>,以便可以向其中添加一些项目。

最佳答案

这是我用来操作现有 AppSetting 的一些代码:

Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.AppSettings.Settings["PrinterID"].Value = "Some Value";
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("appSettings");

要添加新的 AppSetting,您可以将第二行更改为:

config.AppSettings.Settings.Add("PrinterID", "Some Value");

关于c# - 是否可以使用代码将项目添加到 C# 设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14406494/

相关文章:

javascript - InDesign : is it possible to store . .indd 文件内的 jsx 脚本首选项?

android - 无法在 Android 中以编程方式应用系统屏幕亮度

c# - Winforms 首选项值

c# - HttpUtility.UrlDecode 有什么意义

c# - 为什么我们需要 C# 委托(delegate)

C#生成两个小数之间的随机小数

settings - 如何为规则设置 Fiddler2 首选文本编辑器?

c# - .NET正则表达式识别 `if .. then .. else .. endif`

时间:2019-03-17 标签:c#WebAPIlocalization

iphone - 从应用程序启动 iPhone 设置屏幕?