Click here to Skip to main content
15,899,474 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Here is my problem:

I have a windows form through which i set the value of a inter to 5.

int a = 5;

Now when i close the application the value has to be stored somewhere. Again when the application is started the stored value has to be shown.

I am working in windows form application.


I there a way to achieve this without file stream ?

Any kind of help would be appreciated.
Posted
Comments
Sergey Alexandrovich Kryukov 27-Jan-15 23:02pm    
What does it mean? Why without? Do you really know what happens to your computer where the power is disconnected?
—SA

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.
 
Share this answer
 
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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900