C# Properties.Settings 属性不设置任何值

标签 c# settings application-settings

我想在“MyProject.Properties.Settings.Default.Property”中更改值,但给我错误和这个错误;

Severity Code Description Project File Line Suppression State Error CS0200 Property or indexer 'Settings.Version' cannot be assigned to -- it is read only

我该如何解决这个问题?或者我可以尝试哪种不同的方法?

21.03.2017 编辑 - 我用这种方法解决了问题

Properties.Settings.Default["Version"] = File.GetLastWriteTime(mainDllPath).ToString("ddMMyyyyhhmmss");
Properties.Settings.Default.Save();

最佳答案

来自 Microsoft :

Settings that are application-scoped are read-only, and can only be changed at design time or by altering the .config file in between application sessions. Settings that are user-scoped, however, can be written at run time just as you would change any property value. The new value persists for the duration of the application session. You can persist the changes to the settings between application sessions by calling the Save method.

How To: Write and Persist User Settings at Run Time with C#:

Access the setting and assign it a new value as shown in this example:

Properties.Settings.Default.myColor = Color.AliceBlue;

If you want to persist the changes to the settings between application sessions, call the Save method as shown in this example:

Properties.Settings.Default.Save();

User settings are saved in a file within a subfolder of the user’s local hidden application data folder.

You can find more about using settings in c# here .

关于C# Properties.Settings 属性不设置任何值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42905689/

相关文章:

带有特殊字符的 C# 字符串到 MySQL varchar 列

c# - .NET 中令人尴尬的可并行任务

browser - 禁用 HTML TextField 下拉建议框

c++ - C++ 应用程序中的持久数据/设置

c# - ApplicationSettingsBase 为自定义集合写入空标签

c# - 将 List<T> 转换为 HashTable

c# - 为什么线程和任务之间的性能差异如此之大?

c# - 如何在不同的解决方案之间共享同一个 Visual Studio 项目?不同的 app.config 和 settings.settings

c# - 为什么我无法从与设置文件相同的项目/程序集中为设置选择自定义类型?

java - Jenkins 。如何在每次构建期间停止运行测试?