C#: How to remove items from the collection of a IDictionary<E, ICollection<T>> with LINQ?
- by Rosarch
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?