Reputation: 34198
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
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
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