-2
I’m trying to implement a list comparison method that checks if they are equal.
It must return true when the two lists passed by parameter are exactly equal (number of elements, elements and sorting).
I managed 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 the elements, ie, {"a", "b", "c"}
and {"c", "b", "a"}
he regards as equal.
How do I get him to consider ordination? I also wanted him to be able to receive other types of collections and not just strings, that is, to accept ICollection<int>
, ICollection<double>
, ICollection<string>
, ICollection<byte>
. Otherwise I’d have to overload.