I do something like this and the value in the collection doesn’t change
[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};
}
If you change the
var source = GetFoos();intovar source = GetFoos().ToList();, the list is read immediately (and in full). Then you should be able to change the values.Don’t forget to store the changed values or else they revert the next time you read them.