If I have a method that has a params parameter, can it be passed by reference and updated every time a yield is called.
Something like this:
public static void GetRowsIter(ref params valuesToUpdate)
{
foreach(row in rows)
{
foreach(param in valuesToUpdate
{
GetValueForParam(param)
}
yield;
}
}
Is that legal? (I am away from my compiler or I would just try it out.)
No.
paramsjust creates an array that contains the parameters being passed. This array, like all others, is just a collection of variables, and it’s not possible to declare arefvariable or array type. Because of this only actual explicit parameters can be passed asreforout.That being said, if the type is a reference type then it will exhibit reference type semantics as usual, meaning that any changes made to the object will be reflected in all code that has access to that reference. Only assignments to the actual variable would not be reflected.
However, I’m not certain exactly what your code is intended to do. The
yieldstatement either has to be followed by thereturnstatement and a value or by thebreakstatement, which ends the iterator.