I am a little new to c#. I was wondering, is there a simple way to save and retrieve a variable. I have written a program that when it closes, needs to save the variable so when I starts up again that the program stays in the same state from the last time it was executed. The program controls a fan, so if the fan was set to high for the last state, when the program starts again, I need the fan to run at high speed instead of starting at a different speed. Didn't know if simple enough to save to an excel file or is there something simpler.
Asked
Active
Viewed 38 times
0
-
1What type of application? Try this: https://msdn.microsoft.com/en-us/library/bb397750(v=vs.110).aspx – Peter Bons Mar 25 '17 at 18:33
-
You can just save the value to a file and read it back in when you next execute the Program or you can store the value in the Registry and retrieve it from there. .NET has a Registry class to help with this but research a lot before mucking about with the Registry. You can store your value in the Application Setting of your Program. Peter's link will explain more on this. – dannyhut Mar 25 '17 at 18:40
1 Answers
0
Use json or xml to store your settings data. OnWindowloaded retrieve your settings from the respective file and update to it.
or
You can also define a custom configuration section and then put the settings in a separate config file if you didn't want to clutter up your app.config. A custom configuration module allows you to define a structure for your own complex settings and store them in a standard config file. If you have used Entity Framework, Enterprise Library or the like, then you have probably seen them defined at the top of the file. A quick search on Google turned up another StackOverflow post on the subject.

Community
- 1
- 1

Thiyagu Rajendran
- 663
- 4
- 21