Changes to an IEnumerable are not being kept between queries
.net, c#, ienumerable, linq
Solution
Each time you enumerate the `stories` variable, the `Select` call runs again, creating a new set of `Story` objects.
Therefore, each `foreach` loop runs on a different set of `Story` instances.
You need to force the LINQ calls to evaluate exactly once by calling `.ToArray()`. Looping through the resulting array will not re-evaluate the LINQ calls (since it's a normal array), so you'll share the same set of `Story` instances.
Problem
`IEnumerable` is a query that is lazily evaluated. But apparently my understanding is a bit flawed. I'd expect the following to work: ``` // e.Result is JSON from a server JObject data = JObject.Parse(e.Result); JsonSerializer serializer = new JsonSerializer(); // LINQ query to transform the JSON into Story objects var stories = data["nodes"].Select( obj => obj["node"]).Select( storyData => storyOfJson(serializer, storyData)); // set a value on each story returned by the query foreach (Story story in stories) { story.Vid = vid; } // run through the query again, making sure the value was actually set foreach (Story story in stories) { // FAILS - story.VID is 0 Debug.Assert(story.Vid == vid); } ``` What am I misunderstanding here? How can I alter the results of what this query returns?