J'ai deux Listes de Listes :
(1) variantes et (2) options .
J'ai besoin de voir si TOUTES les options existent dans les variantes (indépendamment de l'ordre).
Par exemple, dans le code ci-dessous, je dois m'assurer que chaque liste d'éléments apparaît dans la liste des variantes. Ainsi, les listes "bleu", "rouge" et "vert" doivent apparaître dans la liste des variantes, quel que soit leur ordre.
EDIT (clarification) : Toutes les listes contenues dans "options" doivent apparaître dans "variants". Si l'une d'entre elles échoue, le booléen doit renvoyer false.
J'ai configuré une condition LINQ mais je ne sais pas pourquoi elle ne fonctionne pas. Toute aide serait appréciée.
//TEST 1
List<List<string>> variants = new List<List<string>>();
variants.Add(new List<string> {"cars", "boats", "planes"});
variants.Add(new List<string> {"money", "trees", "plants"});
variants.Add(new List<string> {"green", "blue", "red" });
variants.Add(new List<string> {"kid", "adult", "senior"});
variants.Add(new List<string> {"tax", "insurance", "salary"});
List<List<string>> options = new List<List<string>>();
options.Add(new List<string> { "senior", "adult", "kid" });
options.Add(new List<string> { "blue", "red", "green"});
options.Add(new List<string> {"money", "trees", "plants"});
bool exists = variants.Any(a => options.Any(b => b.SequenceEqual(a.OrderBy(x => x))));
Console.WriteLine(exists);
// The result should be TRUE even though the order of "senior", "adult" and "kid"
// is different and that the order of listed items is different
//TEST 2
List<List<string>> options2 = new List<List<string>>();
options2.Add(new List<string> { "senior", "adult", "kid" });
options2.Add(new List<string> { "orange", "red", "green"});
options2.Add(new List<string> {"money", "trees", "plants"});
exists = variants.Any(a => options2.Any(b => b.SequenceEqual(a.OrderBy(x => x))));
Console.WriteLine(exists);
// The result should be FALSE. All listed options are TRUE except that the 2nd list has
// "orange" which doesn't appear in the variants list.
//TEST 3
List<List<string>> options3 = new List<List<string>>();
options3.Add(new List<string> { "senior", "red", "adult" });
options3.Add(new List<string> { "blue", "kid", "green"});
options3.Add(new List<string> {"money", "trees", "plants"});
exists = variants.Any(a => options3.Any(b => b.SequenceEqual(a.OrderBy(x => x))));
Console.WriteLine(exists);
// The result should be FALSE. All of the items actually exist in the variant list,
// but "senior", "kid", and "adult" do not appear together within a list of variants.