C
C#2y ago
Raki

✅ How to check whether a given list is present in the List of list

I have a List<List<int>> candidates and before adding into it want to check whether a list is already present. The condition is true all the time. How to implement the check condition for each addition
var temp = new List<int>(tempList);
if(!candidates.Any(x => x == temp))
{
candidates.Add(temp);
}
var temp = new List<int>(tempList);
if(!candidates.Any(x => x == temp))
{
candidates.Add(temp);
}
5 Replies
Aaron
Aaron2y ago
are you trying to make sure none of the lists in candidates have the same contents as the new list?
Raki
Raki2y ago
yes. Currently Candidates are the output which has duplicates need to remove the duplicates.
Aaron
Aaron2y ago
do SequenceEquals instead of == in the Any == is checking reference equality
Raki
Raki2y ago
thanks that helped to solve it
Accord
Accord2y ago
Closed!
Want results from more Discord servers?
Add your server