How to use settings in Visual C#

余生长醉 提交于 2019-12-03 18:01:25

问题


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:


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#




回答2:


Kinda like this:

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

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




回答3:


// Retrieving connection string from Web.config.
String connStringMSQL = WebConfigurationManager.ConnectionStrings["andi_msql"].ToString();

In my case this was for my connectionStrings setting but depending on what node your setting is in you can change this accordingly.

Hope this helps



来源:https://stackoverflow.com/questions/650555/how-to-use-settings-in-visual-c-sharp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!