Cannot assign to 'variable' because it is a 'read-only variable type'
This error occurs when an assignment to variable occurs in a read-only context. Read-only contexts include foreach iteration variables, using variables, and fixed variables. To resolve this error, avoid assignments to a statement variable in using blocks, foreach statements, and fixed statements.
The following example generates error XS1656 because it tries to replace complete elements of a collection inside a foreach loop. One way to work around the error is to change the foreach loop to a for loop. Another way, not shown here, is to modify the members of the existing element; this is possible with classes, but not with structs.
The following sample demonstrates how XS1656 can be generated in other contexts besides a foreach loop:
// XS1656.prg
// compile with: /unsafe