I want to store values permanently in a variable. The same variable should be able to be edited and saved by user, and whatever it is I need the value of the variable from the last time I modified it, like a database. Please explain me with some examples!
Asked
Active
Viewed 9,436 times
2
-
2depending on whether you application is multi user etc then the simplest solution would be to use the built in Settings in .net your question doesnt really give enough information but you could check here for a start... http://msdn.microsoft.com/en-us/library/aa730869(v=vs.80).aspx – WraithNath Jul 24 '12 at 14:16
-
1A bit more information would be useful, what kind of application are you building? Windows? Web? – Nigel B Jul 24 '12 at 14:16
-
2Um, write it to a file. Your question does not should that least bit of evidence that you have done research first, or tried to solve it on your own. – GrayFox374 Jul 24 '12 at 14:16
5 Answers
3
You can't. You need persistent storage for this (database, file, registry, etc)

Sergey Berezovskiy
- 232,247
- 41
- 429
- 459
2
Depending on your application you can save your variables for example in a config file or database.
After your application gets started again you load the settings.
2
write the data in a file. when you than restart the application you can read the parameters out of this file and set some variables.
file could mean - sql, db, ini or whatever you are using.
all the best

devanand
- 5,116
- 2
- 20
- 19
1
you can use Properties.Settings advantage is that you can Save a variable per user scope or have Application scope at the same time
internal class Program
{
private static void Main(string[] args)
{
Properties.Settings1.Default.Test = "StackOverFlow";
Properties.Settings1.Default.Save();
Console.ReadKey();
}
}

HatSoft
- 11,077
- 3
- 28
- 43