If I understand you correctly, you want to search through all the lists in a List<List<int>>
to see if any contain a set of numbers, and if none do, then add the numbers as a new list.
One way to do this is using Linq:
public static void AddListIfNotExist(List<List<int>> lists, List<int> newList)
{
if (lists == null || newList == null) return;
if (!lists.Any(list => newList.All(item => list.Contains(item))))
{
lists.Add(newList);
}
}
In use it might look like:
var lists = new List<List<int>>
{
new List<int> { 0, 1, 2, 3 },
new List<int> { 4, 5, 6 },
new List<int> { 23, 24, 25, 28 }
};
var newList1 = new List<int> { 0, 1, 2 };
var newList2 = new List<int> { 9, 10 };
AddListIfNotExist(lists, newList1);
AddListIfNotExist(lists, newList2);
>` and `List`, and show what you've attempted that's not working.
– Rufus L Jan 08 '21 at 17:04