Irakli Lekishvili
Irakli Lekishvili

Reputation: 34198

saving state between program restarts

How can I declare a variable which would save sting forever?

I mean if the user closes and restarts the program, this string value is not lost.

How can this be done?

Upvotes: 3

Views: 13453

Answers (4)

Bryan Crosby
Bryan Crosby

Reputation: 6554

You could save it to a file, a database, a USB drive, somewhere in the cloud... somewhere other than the computer's memory.

Here's a quick example in C# (to write to a file):

string someString = "I will be here forever... well kind of";

using (StreamWriter outfile = new StreamWriter(@"C:\myfile.txt"))
{
   outfile.Write(someString);
}

Upvotes: 2

ccozad
ccozad

Reputation: 1129

There are a number of different ways to store state for an application. The approach really depends on the type of data you are storing and other requirements

Options

Upvotes: 7

Jordan
Jordan

Reputation: 32552

I recommend a database, in particular SQLite.

Upvotes: 1

Orn Kristjansson
Orn Kristjansson

Reputation: 3485

Save the variable value to a database or other storage.

Upvotes: 3

Related Questions