I am trying to do the following… (Foo is a class)
void Main()
{
var foos = ...
DoSomeWork(foos);
// I want all foos to have Bar set to 42
}
public static void DoSomeWork(IEnumberable<Foo> foos)
{
foreach (var foo in foos)
{
foo.Bar = 42;
}
}
class Foo
{
String blahblah;
Int32 Bar;
}
But all the foos have their original values. How do I change them on a ref parameter?
It could be that
foosis a generatingIEnumerable. Example:You can never mutate the values being generated, as they will be freshly created each time you iterate over
foos.Now if you did the following as suggested by @YuriyRozhovetskiy, it will work.
Now we can mutate happily 🙂