Why SequenceEqual for List returns false?

前端 未结 3 1535
忘了有多久
忘了有多久 2020-12-18 00:29

Hi I have some problems with sequenceEqual when I have situation like this:

Sentence s1 = new Sentence { Text = \"Hi\", Order = 1 };
Sentence s2 = new Senten         


        
3条回答
  •  感动是毒
    2020-12-18 01:30

    As the MSDN states here:

    Determines whether two sequences are equal by comparing the elements by using the default equality comparer for their type.

    Sentence in your case is a reference type with default Equals and GetHashCode, which means it will be using referential equality for each element.

    You can always use the overload which accepts IEqualityComparer

提交回复
热议问题