【发布时间】:2011-09-06 00:53:03
【问题描述】:
我在 Silverlight 工具包中看到过类似以下的代码,但不明白这样做的安全性:
private void ItemsSourceCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
// Update the cache
if (e.Action == NotifyCollectionChangedAction.Remove && e.OldItems != null)
{
for (int index = 0; index < e.OldItems.Count; index++)
{
_items.RemoveAt(e.OldStartingIndex);
}
}
}
如果您从说索引 5 中删除一个项目,这不会将索引 5 之后的 _items 集合中每个项目的当前索引更改为比以前少一个吗?那么,像这段代码那样使用“旧”索引不断删除项目是安全的吗?
我真的很想知道为什么会这样。
有什么想法吗?
【问题讨论】:
标签: wpf silverlight observablecollection inotifycollectionchanged