Possible Duplicates:
Exception during iteration on collection and remove items from that collection
How to remove elements from a generic list while iterating around it?
Better way to remove matched items from a list방법을 제대로 목록에서 항목을 제거
// tmpClientList is List<Client> type
if (txtboxClientName.Text != "")
foreach (Client cli in tmpClientList)
if (cli.Name != txtboxClientName.Text)
tmpClientList.Remove(cli);
오류 : ". 컬렉션이 수정되었다 열거 작업이 실행되지 않을 수 있습니다"
몇 가지 간단한 방법으로 목록의 항목을 다른 목록이나 배열에 저장하지 않고 코드의 다른 위치에서 항목을 제거하지 않고 목록에서 항목을 제거 할 수 있습니까? 또한 RemoveAt (인덱스)를 시도했지만 루프가 실행될 때 수정되는 것과 정확히 똑같은 상황입니다.
정확한 중복 문제에 동의, 링크 1 참조 http://stackoverflow.com/questions/1154325/better-way-to-remove-matched-items-from-a-list and link two : http : //stackoverflow.com/questions/1541777/can-you-remove-an-item-from-a-list-whilstiterating-through-it-in-c – CrimsonX