It might help to visualize this:
A:
A[0]:
A[0][0]: 1
A[1]:
A[1][0]: 2
B:
B[0]:
B[0][0]: 1
When you call A.Contains()
, you're asking whether the thing you're testing is either A[0]
or A[1]
. Since you're passing it B
, and B
is neither of those two, it returns false. Even if you were to pass it B[0]
or B[0][0]
, you'd still get false, because none of those are the same object as A[0]
or A[1]
.
SequenceEqual()
is the function which will test whether the contents of two List
are the same. So you want to test whether either A[0]
or A[1]
is SequenceEqual
to B[0]
(i.e. either A[0][0] == B[0][0]
or A[1][0] == B[0][0]
).
The best way to do this is with the LINQ function .Any()
. A.Any(a => a.SequenceEqual(B[0]))
will test B[0]
against everything in A
. If you want to compare all B
elements to all A
elements, you'd need something more like A.Any(a => B.Any(b => a.SequenceEqual(b))
. This can be translated as:
foreach (var a in A) // A[0], A[1], etc.
{
foreach (var b in B) // B[0], B[1], etc.
{
// is our current a value matching the current b value?
// i.e. A[0] is exactly the same as B[0] on the first pass
if (a.SequenceEqual(b)) return true;
}
}
return false;