Sudheer Kumar

Sudheer Kumar

  • NA
  • 105
  • 10.4k

how to edit or modify a list collection which is iterating

Jan 6 2017 2:23 AM
i am having two list collections one for new persons and one for existing persons and my condition is if the record in new person matches with existing person it should remove the record from existing person for that i am using the following code
 
 foreach(var p in existingperson)
{
if(newperson.id==p.id)
{
 existingperson.remove(p);
return true;
}
else
{
return false;
}
}
 
its throwing an exception that i cant change collection in iteration.for using for loop i dont know the count of existing records..please help

Answers (2)