I'm trying to implement a list comparison method that checks to see if they match.
It should return true when the two lists passed by parameter are exactly the same (number of elements, elements and ordering).
I was able to develop part of the solution:
public bool ListasIguais(ICollection<string> x, ICollection<string> y)
{
if (x.Count != y.Count)
return false;
return x.Except(y).Count() == 0 ? true : false;
}
But he is not considering the order of elements, that is, {"a", "b", "c"}
and {"c", "b", "a"}
he considers as equal.
How do I consider the ordination? I also wanted it to be able to receive other types of collections, not just strings, that is, it accepts ICollection<int>
, ICollection<double>
, ICollection<string>
, ICollection<byte>
. Otherwise I would have to overload.