【发布时间】:2010-10-13 15:03:58
【问题描述】:
我长期从事 VB.net 开发,最近改用 C#。
当我使用 VB.net 调用用户设置时,我只需要使用设计器创建一个新设置,然后使用 My 命名空间从代码中调用它。
这是代码My.settings.anysetting
我可以更改或从中获取数据。
但是在 C# 中,My 关键字不起作用,那么我该怎么做才能调用设置??
【问题讨论】:
我长期从事 VB.net 开发,最近改用 C#。
当我使用 VB.net 调用用户设置时,我只需要使用设计器创建一个新设置,然后使用 My 命名空间从代码中调用它。
这是代码My.settings.anysetting
我可以更改或从中获取数据。
但是在 C# 中,My 关键字不起作用,那么我该怎么做才能调用设置??
【问题讨论】:
Settings 存储在 Application 文件夹下,因此,将其用作它们的命名空间。
int myInt = Properties.Settings.Default.myVariable;
Properties.Settings.Default.myVariable = 12;
Properties.Settings.Default.Save();
【讨论】:
Application吗?看起来 Properties 是这里的命名空间(在我的实际应用程序中)。
有点像这样:
this.BackColor = Properties.Settings.Default.myColor;
文档: https://msdn.microsoft.com/en-us/library/bb397759(v=vs.110).aspx
【讨论】:
// Retrieving connection string from Web.config.
String connStringMSQL = WebConfigurationManager.ConnectionStrings["andi_msql"].ToString();
在我的情况下,这是我的 connectionStrings 设置,但根据您的设置所在的节点,您可以相应地更改它。
希望对你有帮助
【讨论】: