Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use settings in Visual C#

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??

like image 453
Omar Abid Avatar asked Mar 16 '09 14:03

Omar Abid


People also ask

How do I access Visual Studio settings?

To open the Settings editor, use the following VS Code menu command: On Windows/Linux - File > Preferences > Settings. On macOS - Code > Preferences > Settings.

How do I change Visual Studio settings?

To change your development settings after you open Visual Studio for the first time, follow these steps: Select Tools > Import and Export Settings from the menu bar to open the Import and Export Settings Wizard. In the Import and Export Settings Wizard, select Reset all settings, and then select Next.

How do I open preferences in Visual Studio?

For instance, Visual Studio Code has a "preferences" submenu in its file menu, whereas Visual Studio has most of its options available under "Tools->Options".

How do I create a settings file in Visual Studio?

In Visual Studio, from the Project menu, choose Add New Item. The Add New Item dialog box opens. In the Add New Item dialog box, select Settings File, enter a name for the file, and click Add to add a new settings file to your solution. In Solution Explorer, drag the new Settings file into the Properties folder.


1 Answers

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#

like image 114
Samuel Avatar answered Sep 22 '22 11:09

Samuel