I'm programming in c#. I'm trying to remove an item from a List<>
but when I remove the item I get this exception error:
An exception of type 'System.InvalidOperationException' occurred in mscorlib.dll but was not handled in user code
Additional information: Collection was modified; enumeration operation may not execute.
Here is my code:
foreach (Target t in targetList)
{
if (t.CalculateDistance(t.EndX, t.EndY) <= 5)
{
targetList.Remove(t);
}
}
I get exception on first line. Why do I see this error? or How can I fix it?