bullets.RemoveAll(bullet => bullet.Offscreen());
편집 :-그대로는이 작품을 만들려면 실버 라이트에서 프로젝트에 다음 확장 메소드를 추가하십시오.
List<T>.RemoveAll
처럼이 알고리즘은 O (N)입니다. 여기서 N은 목록에서 제거 된 요소의 수인 M (O * N)과 대조되는 목록의 길이입니다. 비 Silverlight 프레임 워크에서 발견 된 RemoveAll
메서드와 동일한 프로토 타입을 사용하는 확장 메서드이기 때문에 사용할 수있는 경우 기본 제공 메서드가 사용되며이 메서드는 Silverlight 빌드에 완벽하게 사용됩니다.
public static class ListExtensions
{
public static int RemoveAll<T>(this List<T> list, Predicate<T> match)
{
if (list == null)
throw new NullReferenceException();
if (match == null)
throw new ArgumentNullException("match");
int i = 0;
int j = 0;
for (i = 0; i < list.Count; i++)
{
if (!match(list[i]))
{
if (i != j)
list[j] = list[i];
j++;
}
}
int removed = i - j;
if (removed > 0)
list.RemoveRange(list.Count - removed, removed);
return removed;
}
}
이 질문을 참조하십시오.com/questions/308466/enumerable-collection-while-iterating-throu에서 아이템을 수정하거나 삭제하는 방법 –