我做這樣的事情,並集合中的值不會更改爲什麼我不能編輯IEnumerable的元素?
[Test]
public void EnumerableTest()
{
var source = GetFoos();
source.First().One = "hello";
Assert.AreEqual(source.First().One, "hello");
//it fails
}
//I actually return this from a repository
public IEnumerable<Foo> GetFoos()
{
yield return new Foo() {One = "1", Two = "2", Three = true};
yield return new Foo() {One = "1", Two = "2", Three = true};
yield return new Foo() {One = "1", Two = "2", Three = true};
}
IsEqualTo()?嘗試使用Equals()。 – tgiphil 2010-06-03 09:00:21
@tgiphil對不起,這是我自己的擴展,它有 – Omu 2010-06-03 09:02:13