Variables declared within a using
statement are read-only (they cannot be assigned after initialization).
Therefore, you cannot pass them as ref
parameters, since the point of ref
parameters is to be assigned.
In your first example, the variable is not declared in the using
statement, so it isn't read-only.
It gives a compiler warning for the same reason that the second variable is read-only.
The reason is that (as the warning states) the using
statement will only dispose the variable's original value.