Search code examples
c#winformsproperties.settings

Using Settings Class in C#


I am using the Properties.Settings class to save the application settings. I would like to know, once I deploy in the client system, whether the settings would be saved across application restart and system restart.

Consider the scenario :

Once the application is deployed, the user would save the Mobile Number through a UI as

Phone : 1xxxx - 45678

Now, I would save the Phone number as

 Properties.Settings.Default.ClientPhone = this.PhoneText.Text;
 Properties.Settings.Default.Save();

Am I understand, that the phone number would be saved in the application across app.restarts and reboots?


Solution

  • This is the difference about application and user settings. Application settings are read only. User settings are stored permanently on a per-user basis. Your code is exactly what it takes to change and save a user setting.

    Please note: As they are called "user settings", they will be stored separately for every user on the machine! You can not, using the default .NET settings mechanism, create changeable settings that are the same for all users.

    Do not re-invent the wheel! Use the .NET settings mechanism - you're doing it right in your example :-)