嗨,当我遇到这样的情况时,我对sequenceEqual有一些问题:
Sentence s1 = new Sentence { Text = "Hi", Order = 1 };
Sentence s2 = new Sentence { Text = "Hello", Order = 2 };
List<Sentence> list1 = new List<Sentence> { s1, s2 };
List<Sentence> list2 = new List<Sentence> { s1, s2 };
这很好用
bool equal = list1.SequenceEqual(list2);
并返回true
;
但是当我有一些返回List<Sentence>
例如的方法时:
public List<Sentence> Getall()
{
Sentence s1 = new Sentence { Text = "Hi", Order = 1 };
Sentence s2 = new Sentence { Text = "Hello", Order = 2 };
return new List<Sentence> { s1, s2 };
}
并像这样使用它:
List<Sentence> list1 = Getall();
List<Sentence> list2 = Getall();
然后简单地检查一下
bool equal = list1.SequenceEqual(list2);
它返回'false',请告诉我为什么?以及如何使其工作?