【问题标题】:Application Settings saving应用程序设置保存
【发布时间】:2010-12-21 00:38:19
【问题描述】:

我的应用程序中有两个程序集。 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

我的方法有什么问题?

【问题讨论】:

    标签: c# application-settings


    【解决方案1】:

    在设置设计器中,确保 FullNameOfTheUser 的 Scope 属性设置为“用户”。如果您创建应用程序范围的设置,它将作为只读属性生成。请查看this article 了解更多信息。

    【讨论】:

      【解决方案2】:

      设置需要有用户,而不是应用范围。

      【讨论】:

        猜你喜欢
        • 2011-07-19
        • 1970-01-01
        • 2017-03-14
        • 1970-01-01
        • 2016-06-10
        • 2013-06-19
        • 1970-01-01
        • 1970-01-01
        • 2011-12-23
        相关资源
        最近更新 更多