I have a list of custom objects named _interestlist
. Now I want to remove all the items in this list which have "active" member is set to false. and I wrote some thing like this
int counter = 0;
foreach (var interest in _interestlist)
{
if (interest.active==false)
{
_interestlist.Remove(interest);
}
counter++;
}
But this throws an error like this
Collection was modified; enumeration operation may not execute.
Isn't this operation possible through a loop? IS there any other way to achieve this?