How to use settings in Visual C#


Question

I have been a VB.net developer for a long time and changed recently to C#. When I was using VB.net, to call user settings, I just need to create a new setting using the designer and then call it from code with the My namespace.
Here's the code
My.settings.anysetting
I can change or get data from it. However in C# the My keyword doesn't work, so what can I do to call settings??

1
13
3/16/2009 2:30:51 PM

Accepted Answer

Settings are stored under the Application folder and as such, use that as their namespace.

int myInt = Properties.Settings.Default.myVariable;
Properties.Settings.Default.myVariable = 12;
Properties.Settings.Default.Save();

Using Settings in C#

28
3/16/2009 2:07:14 PM

Kinda like this:

this.BackColor = Properties.Settings.Default.myColor;

Documentation: https://msdn.microsoft.com/en-us/library/bb397759(v=vs.110).aspx


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon