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
为什么啊???
{
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
为什么啊???
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;
}
} 你能说一下红字的部分是什么意图么?
{
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;
}
}
如果是,get方法: get
{
if (_hasChanged) return true;
bool result=false;
foreach (Photograph p in this)
{
if (p.HasChanged)
{
result=true;
break;
}
}
return result;
}