Unable to remove list item from list inside a for each loop C# [duplicate]
问题 This question already has answers here : What is the best way to modify a list in a 'foreach' loop? (11 answers) Closed 6 years ago . 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