如何创建永久内存? [英] How Do I Create A Permanene Memory ?

查看:107
本文介绍了如何创建永久内存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的问题:



我有一个Windows窗体,通过它我将inter的值设置为5.



int a = 5;



现在当我关闭应用程序时,值必须存储在某个地方。再次启动应用程序时,必须显示存储的值。



我在Windows窗体应用程序中工作。




我有没有办法实现这个没有文件流?



任何形式的帮助都将不胜感激。

推荐答案

您需要写入文件,数据库或Windows注册表。您的程序在RAM中运行,并且所有内存在退出时都会释放/丢失。除了永久(实际上是持久的)存储(例如HDD)之外没有办法保存。
You need to write to a file, database or windows registry. Your program runs in RAM and all memory is released/lost when it exits. There's no way to save except to permanent (actually persistent) storage such as HDD.


在WinForms中保持变量值的一种方法是使用Application.Settings:[ ^ ]。



这里有一个关于如何使用Application.Settings的CodeProject的好教程:[ ^ ]。



但是,我建议你只使用Application.Settings确切地说明了这个名称的含义:Applcation的全局设置:默认BackGroundColor,字体,窗口大小等等。



如果你有很多你希望跨会话存储其值的变量,那么我认为你应该创建一个Class来保存这些变量及其值,并将Class序列化为一个文件,然后de-seriali当您的应用程序启动时,它就会结束。



有很多很好的例子可以显示/教你如何在CodeProject上序列化和反序列化类。
One way to make variable values persist in WinForms is to use Application.Settings: [^].

There's a good tutorial here on CodeProject on how to use Application.Settings: [^].

However, I suggest you only use Application.Settings for exactly what that name implies: global settings for your Applcation: things like default BackGroundColor, Font, Window Sizes, etc.

If you have a lot of variables whose value you wish to store across sessions, then I think you should create a Class to hold those variables and their values and serialize the Class to a file, and then de-serialize it when your Application starts.

There are many good examples that show/teach you how to serialize and de-serialize a Class on CodeProject.


这篇关于如何创建永久内存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆