C#: How to remove items from the collection of a IDictionary<E, ICollection<T>> with LINQ?
Posted
by Rosarch
on Stack Overflow
See other posts from Stack Overflow
or by Rosarch
Published on 2010-04-23T17:10:33Z
Indexed on
2010/04/23
17:13 UTC
Read the original article
Hit count: 316
Here is what I am trying to do:
private readonly IDictionary<float, ICollection<IGameObjectController>> layers;
foreach (ICollection<IGameObjectController> layerSet in layers.Values)
{
foreach (IGameObjectController controller in layerSet)
{
if (controller.Model.DefinedInVariant)
{
layerSet.Remove(controller);
}
}
}
Of course, this doesn't work, because it will cause a concurrent modification exception. (Is there an equivalent of Java's safe removal operation on some iterators?) How can I do this correctly, or with LINQ?
© Stack Overflow or respective owner