Compiler Error CS1933


Updated: July 20, 2015

For the latest documentation on Visual Studio 2017 RC, see Visual Studio 2017 RC Documentation.

Expression cannot contain query expressions

Some variables cannot be initialized with a query expression. Constants cannot be initialized with query expressions because constants may only be initialized with some combination of literals, named constants, and mathematical operators.

To correct this error

  1. Remove the modifier from the query variable.

The following example generates CS1933:

// cs1933.cs  
using System.Linq;  
using System.Collections;  
class P  
    const IEnumerable e = from x in new[] { 1, 2, 3 } select x; // CS1933  
    static int Main()  
        return 1;  

LINQ Query Expressions