Compiler Error CS1947
Range variable 'variable name' cannot be assigned to -- it is read only.
A range variable is like an iteration variable in a foreach
statement. It cannot be assigned to in a query expression.
To correct this error
Remove the assignment to the range variable.
If necessary, introduce a new range variable by using the
let
clause and use it to store the value.
Example
The following code generates CS1947:
// cs1947.cs
using System.Linq;
class Test
{
static void Main()
{
int[] array = new int[] { 1, 2, 3, 4, 5 };
var x = from i in array
let k = i
select i = 5; // CS1947
x.ToList();
}
}
See also
Collaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide.
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for