您好我有一些問題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