首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

编辑属性时出现的有关问题

2012-02-21 
编辑属性时出现的问题?publicclass PhotoAlbum : CollectionPhotograph,IDisposable{private bool _hasC

编辑属性时出现的问题?
public class PhotoAlbum : Collection<Photograph>,IDisposable
  {
  private bool _hasChanged = false;

  public bool HasChanged
  {
  get
  {
  if (_hasChanged)

  return true;

  foreach (Photograph p in this)
  {
  if (p.HasChanged)
  return true;
  return false;
  }
  }
  internal set
  {
  _hasChanged = value;
  if (value == false)
  {
  foreach (Photograph p in this)
  p.HasChanged = false;
  }
  }


  }
  public Photograph Add(string fileName)
  {
  Photograph p = new Photograph(fileName);
  base.Add(p);
  return p;
  }

  protected override void InsertItem(int index, Photograph item)
  {
  base.InsertItem(index, item);
  HasChanged = true;
  }
  protected override void RemoveItem(int index)
  {
  Items[index].Dispose();
  base.RemoveItem(index);
  HasChanged = true;
  }
  protected override void SetItem(int index, Photograph item)
  {
  base.SetItem(index, item);
  HasChanged = true;
  }
  public void Dispose()
  {
  foreach (Photograph p in this)
  p.Dispose();
  }
  protected override void ClearItems()
  {
  if (Count > 0)
  {
  Dispose();
  base.ClearItems();
  HasChanged = true;
  }
  }

  }
}
编译时报错:错误1“Manning.MyPhotoAlbum.PhotoAlbum.HasChanged.get”: 并非所有的代码路径都返回值C:\Documents and Settings\XuShuXiang\My Documents\Visual Studio 2005\Projects\MyPhotos\MyPhotoAlbum\PhotoAlbum.cs1613MyPhotoAlbum
为什么啊???

[解决办法]

C# code
        public  bool HasChanged         {             get             {                 if (_hasChanged)                     return true; [color=#FF0000]                foreach (Photograph p in this) [/color]                {                     if (p.HasChanged)                         return true;                     return false;                 }             }             internal set             {                 _hasChanged = value;                 if (value == false)                 {                     foreach (Photograph p in this)                         p.HasChanged = false;                 }             } 

热点排行