Compiler Error CS1933

表达式不能包含查询表达式

有些变量不能用查询表达式进行初始化。常量不能用查询表达式进行初始化,因为常量只能用文本、命名常量和数学运算符的某一组合进行初始化。

更正此错误

  1. 从查询变量中移除该修饰符。

下面的示例生成 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 查询表达式(C# 编程指南)