简体   繁体   English

C#保存设置

[英]c# save settings

Im building a small project that uses some settings features. 我正在建立一个使用某些设置功能的小项目。 I could change the DB Path and some other textfields. 我可以更改数据库路径和其他一些文本字段。

Whats the best way in c# to save these settings? 用c#保存这些设置的最佳方法是什么? Is there some built in config or ini file that can be changed under runtime? 是否有一些内置的config或ini文件可以在运行时更改? Because if I change the DB Path i need it to do this without restarting the program. 因为如果更改数据库路径,我需要它来执行此操作而无需重新启动程序。 I know i ofc can build a simple textdoc and read from but I whant to use some standard c# way. 我知道我ofc可以建立一个简单的textdoc并从中读取,但是我想使用一些标准的c#方式。

Thx for anyfeedback. Thx的任何反馈。

/Marthin /马丁

If you have a look in the project property pages you can add a settings file. 如果您在项目属性页面中查看,则可以添加设置文件。

To use the settings in code you would do something like: 要使用代码中的设置,您可以执行以下操作:

Properties.Settings.Default.SettingName

Do bare in mind though that these settings are local and would need to be specified on each machine 请记住,尽管这些设置是本地的,并且需要在每台计算机上指定

Here is a link to the settings class on MSDN http://msdn.microsoft.com/en-us/library/aa730869(VS.80).aspx 这是指向MSDN上的设置类的链接http://msdn.microsoft.com/zh-cn/library/aa730869(VS.80).aspx

如果创建新的c#Windows窗体应用程序,则默认情况下具有属性,请尝试在解决方案资源管理器中展开节点,您将找到设置文件,可以在其中添加值,在运行时可以检索并更改它们,更改后它们,您可以通过以下方式保存它们:

Properties.Settings.Default.Save();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM