您好我有一些问题sequenceEqual时,我有这样的情况:为什么序列等于列表<T>返回false?
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);
它返回'假',请告诉我为什么?以及如何使其工作?
。在第一种情况下,它们与两个不同的*引用*完全相同。 – bytefire 2013-02-19 13:02:32