Bonjour à tous, j'ai fait le petit code ci-dessous qui permet de récupérer un liste de doublons dans une liste de string. J'aurais souhaité avoir votre avis sur le code.

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
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
 
class Program
	{
		public static void Main(string[] args)
		{
			Console.WriteLine("Test recherche doublons");
 
			List<string> withdouble = new List<string>(new string[] {"A", "B", "C", "C", "C", "C", "D", "E", "E", "G", "F"} );
 
			List<string> Doublons = new List<string>();
			string BaseCompare = "";
 
			withdouble.Sort(); //On trie par ordre
 
 
			for (int i = 0; i < withdouble.Count; i++)
			{
 
				if ((i+1 < withdouble.Count) && (withdouble[i] == withdouble[i+1]))
				{
					BaseCompare = withdouble[i];
					Doublons.Add(withdouble[i] + " - index : " + i.ToString()); //On ajoute le premier doublons
 
					int j = i; // entier de la boucle imbriquée pour voir si plusieurs doubles
 
					do
					{
						j++;
						if (withdouble[j] == BaseCompare ) Doublons.Add(withdouble[j] + " - index : " + j.ToString());
 
					}while((j+1 < withdouble.Count) && (withdouble[j+1] == BaseCompare));
 
					if (j < withdouble.Count) i = j; else i = withdouble.Count;
				}
 
			}
 
 
			foreach (string s in Doublons)
			{
				Console.Write(s + Environment.NewLine);
			}
 
 
			Console.Write("Press any key to continue . . . ");
			Console.ReadKey(true);
		}
	}
Merci beaucoup.