Bonjour,
Je cherches à parcourir une ArrayList et supprimer certains éléments :
Malheureusement, je me prends cette erreur :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 foreach (Point p in ATraiter) { Console.WriteLine(p.row + "," + p.col); foreach (Point p1 in Traiter) { if ( (p.row > 0 && p1.row == p.row-1 && p1.col == p.col) || (p.col > 0 && p1.col == p.col-1 && p1.row == p.row) || (p1.col == p.col+1 && p1.row == p.row) ) { Console.WriteLine("supprime " + p.row + "," + p.col); ATraiter.Remove(p); Traiter.Add(p); } } }
Comment faire cette suppression proprement ?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5 Unhandled Exception: System.InvalidOperationException: Collection was modified; enumeration operation may not execute. at System.Collections.ArrayListEnumeratorSimple.MoveNext() at Carte.Connexe() in c:\Temp\C#\Lac.cs:line 79 at Client.Main() in c:\Temp\C#\Lac.cs:line 106
Merci par avance pour votre aide.
Laly.
Partager