knights

knights

  • NA
  • 114
  • 125.5k

Exception in Queue while removing an element ?

Dec 9 2010 10:59 AM

I have a queue carrying class objects.Each class object has 3 string properties.In a loop i am checking with an If condition, on one of the class properties and on that basis i want to remove(dequeue) an object.
Suppose in c#.net and some pseudo code following is the scenario.
Foreach Loop to iterate through queue items
if myClassObj==(int)Class.Property1.ToString()
{
   queue.Dequeue(this)
}
EndLoop
I get an exception saying that "Collection was modified after the enumerator was instantiated." Any one got idea about this? and also any alternates are welcome.Cheers

Answers (2)