Equality between two enumerables

前端 未结 2 481
长情又很酷
长情又很酷 2021-01-03 19:46

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

2条回答
  •  清歌不尽
    2021-01-03 19:48

    Have a look at the Enumerable.SequenceEqual method.

    bool result = AllAccounts.SequenceEqual(other.AllAccounts);
    

    Depending on the data type you may also need to use the overloaded method that accepts an IEqualityComparer to define a custom comparison method.

提交回复
热议问题