应用程序设置保存

9

我的应用程序中有两个程序集,分别是MyApplication.BOMyApplication.GUI

我已经为BO程序集配置了属性设置。

现在,当我尝试编译以下代码时:

public class MyApplicationInfo
{
 private string _nameOfTheUser;
 public string FullNameOfTheUser
 {
  get { return _nameOfTheUser; }
  set { _nameOfTheUser = value; }
 } 

 public void Save()
 {
  try
  {
   MyApplication.BO.Properties.Settings.Default.FullNameOfTheUser = this.FullNameOfTheUser;

   MyApplication.BO.Properties.Settings.Default.Save();
  }
  catch (Exception ex)
  {
   throw ex;
  }
 }
}

我在使用VS2005时遇到了以下编译错误:

错误 1 属性或索引器'MyApplication.BO.Properties.Settings.FullNameOfTheUser'不能被赋值,因为它是只读的。F:\CS\MyApplication\MyApplication.BO\MyApplicationInfo.cs 57 17 MyApplication.BO

我的方法有什么问题吗?

2个回答

28
在设置设计器中,确保FullNameOfTheUser的范围属性设置为“User”。如果创建了应用程序范围的设置,则会生成只读属性。请参阅该文章获取更多信息。

2
设置需要具有用户范围,而不是应用程序范围。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接