У меня есть два списка списков:
(1) варианты и (2) параметры .
Мне нужно посмотреть, существует ли ВСЕ опции внутри вариантов (независимо от порядка).
Например: в приведенном ниже коде мне нужно убедиться, что каждый список элементов отображается в списке вариантов - поэтому список «синий», «красный» и «зеленый» должен появляться в списке вариантов независимо от порядка
РЕДАКТИРОВАТЬ (уточнение): Все списки внутри «параметров» должны появляться в «вариантах».Если один из них дает сбой, тогда логическое значение должно возвращать false.
Я установил условие LINQ, но я не уверен, почему оно не работает.Любая помощь будет оценена.
//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.