I ve seen code like the following in the Silverlight toolkit and can t understand how it is safe to do:
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);
}
}
}
If you remove an item from say index 5 doesn t that change the current index of every item in the _items
collection after index 5 to be one less than before? So then how is it safe to continually remove items using their "old" indexes like this code does?
I d really like to understand why this works.
Any ideas?