You can use SequenceEqual
extension method:
var result = list1.All(a => list2.Any(x => x.Item1 == a.Item1 && x.Item2.SequenceEqual(a.Item2)));
Returns true
for your sample input.
The reason why you have to do it explicitly and it's not working by default when two Tuple<string, IEnumerable<string>>
instances are compared is the second Tuple
item. According to MSDN both components are checked agains each other to decide if Tuple
s are equal. Because the second one is an Array
standard reference equality comparer is used. And because your Tuple
s are not pointing to the same Array
in memory it returns false.
Stardard .Any(a.Equals)
would work if only your Tuple
objects were pointing to the same array:
var array = new[] { "value" };
var list1 = new List<Tuple<string, IEnumerable<string>>>
{
Tuple.Create<string,IEnumerable<string>>("string", array)
};
var list2 = new List<Tuple<string, IEnumerable<string>>>
{
Tuple.Create<string,IEnumerable<string>>("string", array)
};
var result = list1.All(a => list2.Any(a.Equals));
Returns true
as well.