This topic has not yet been rated - Rate this topic

Compiler Error CS1932

Visual Studio 2008

Cannot assign 'expression' to a range variable.

The compiler must be able to infer the type of a range variable, whether it is introduced in a from clause or a let clause. It cannot be null because null is not a type, and it cannot be assigned with an expression of an unsafe type.

To correct this error

  • Remove the assignment that is not valid.

  • Explicitly cast the expression to an allowed type

The following code generates CS1932 because the type of the range variable cannot be inferred. Cast the value to the intended type to fix the error, as shown in the following example.

// CS1932.cs
using System.Linq;
class Test
{
    static void Main()
    {
        
        var x = from i in Enumerable.Range(1, 100)
                let k = null // CS1932
                // Try the following line instead.
                let k = (string) null
                select i;
    }
}
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ