C#.NET - 方法来存储一些非常小规模的持续信息?小规模、方法来、信息、NET

2023-09-03 16:18:01 作者:暖不男!

我有需要极少的永久存储的应用程序。实际上,我们在谈论< 30的整数。所有的应用需求是要知道在下次启动这些整数(和整数做改变,因为它运行)。

I have an application that will need extremely little persistent storage. Realistically, we're talking about < 30 integers. All the application needs is to know those integers on next startup (and the integers do change as it runs).

一个数据库是矫枉过正,但我​​并不特别希望只使用一个文本文件,无论是。

A database is overkill for this, but I don't particularly want to just use a text file either.

请问C#有什么机制,坚持小的值这样运行的?我注意到,你可以在里面储存东西的资源文件和一些其他地方 - 我不知道你是否能虽然改变那些在运行时。我刚学C#和放大器; .NET一个新的工作,所以道歉,如果这是一个愚蠢的问题!

Does C# have any mechanism for persisting small values like this between runs? I've noticed you can store things in resource files and some other places - I don't know if you can change those in the runtime though. I'm just learning C# & .NET for a new job, so apologies if this is a silly question!

推荐答案

下面是一个blurp另一SO 帖子,讲述了如何设置应用程序设置,这是读/写值的简单的基于文件的解决方案。

Here is a blurp of another SO post that explains how to setup Application Settings, this is a simple file based solution for reading/writing values.

的如果您使用的Visual Studio则是pretty的容易得到持久化的设置。右键单击Solution Explorer中的项目,选择属性,选择设置选项卡,单击超链接如果设置不存在。使用设置选项卡来创建应用程序设置。Visual Studio中创建的文件Settings.settings和Settings.Designer.settings包含来自ApplicationSettingsBase继承单个类设置。您可以访问这个类您的code读/写应用程序设置:的

"If you work with Visual Studio then it is pretty easy to get persistable settings. Right click on the project in Solution Explorer, choose Properties. Select the Settings tab, click on the hyperlink if settings doesn't exist. Use the Settings tab to create application settings. Visual Studio creates the files Settings.settings and Settings.Designer.settings that contain the singleton class Settings inherited from ApplicationSettingsBase. You can access this class from your code to read/write application settings:"

Settings.Default["SomeProperty"] = "Some Value";
Settings.Default.Save(); // Saves settings in application configuration file
 
精彩推荐
图片推荐