2

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!

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Ulaga
  • 863
  • 1
  • 8
  • 17
  • 2
    depending 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
  • 1
    A bit more information would be useful, what kind of application are you building? Windows? Web? – Nigel B Jul 24 '12 at 14:16
  • 2
    Um, 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 Answers5

4

You need to serialize it somewhere that persists when the computer is rebooted, and then read it when your program starts again. This could be a database, (for simpler DBs, look at something like SQLite) an XML file, etc.

Tim S.
  • 55,448
  • 7
  • 96
  • 122
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.

Community
  • 1
  • 1
dknaack
  • 60,192
  • 27
  • 155
  • 202
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