Overwrite a variable and stay with the value c# -


how can make variable not defined (string name = "";) , when user chooses value (in case path of directory), value (path) kept in memory, doesn't need input again. value should stored, when application restarted, still available.

this global variable:

static class global {     private static string path = "";      public static string globalvar     {         { return path; }         set { path = value; }     } } 

and button action:

private void button1_click(object sender, eventargs e) {     folderbrowserdialog fbd = new folderbrowserdialog();      if (fbd.showdialog() == dialogresult.ok)     {         textbox1.text = fbd.selectedpath;         global.globalvar = textbox1.text;     } } 

there's no such thing "permanent global variable". instead, use builtin configuration mechanisms of .net framework.

in visual studio, open project properties , navigate tab "settings". there's link on right pane saying no default settings created far. click link create settings.

then, add new user setting entering name , selecting type (string, int, etc.). make sure user setting, not application setting, application settings read only. on, can access setting variable using properties.settings.default.settingname.

so save setting permanently between program/machine restarts, use properties.settings.default.save().


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -