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.cs 16 13 MyPhotoAlbum
为什么啊???

解决方案 »

  1.   


            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; 
                    } 
                } 你能说一下红字的部分是什么意图么?
      

  2.   

            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; 
                    } 
                } 
      

  3.   

    internal set 没有返回值!
      

  4.   

    说真的,不太明白你那儿的意图,不知道你是不是要检查所有的Photograph,只要有被修改的就返回true?
    如果是,get方法:            get  
                {  
                    if (_hasChanged)                      return true;  
                    bool result=false;
                    foreach (Photograph p in this) 
                    {  
                        if (p.HasChanged)  
                        {  
                           result=true;
                           break;
                        }  
                    }  
                   return result;
                }  
      

  5.   

    恩,是要遍历Photograph是否被修改的。谢谢dancigbit!真心感谢您的帮助