Equality between two enumerables
Posted
by Berryl
on Stack Overflow
See other posts from Stack Overflow
or by Berryl
Published on 2010-04-02T04:16:28Z
Indexed on
2010/04/02
4:23 UTC
Read the original article
Hit count: 597
I have two enumerables with the exact same reference elements, and wondering why Equals wouldn't be true.
As a side question, the code below to compare each element works, but there must be a more elegant way
Cheers,
Berryl
var other = (ActivityService) obj;
if (!AllAccounts.Count().Equals(other.AllAccounts.Count())) return false;
for (int i = 0; i < AllAccounts.Count(); i++) {
if (!AllAccounts.ElementAt(i).Equals(other.AllAccounts.ElementAt(i))) {
return false;
}
}
return true;
© Stack Overflow or respective owner