编译器错误 CS0838
更新:2007 年 11 月
错误消息
表达式目录树不能包含多维数组初始值设定项。
表达式目录树中的多维数组不能使用数组初始值设定项进行初始化。
更正此错误
- 先创建并初始化该数组,然后再创建表达式目录树。
示例
下面的示例生成 CS0838:
// cs0838.cs
using System;
using System.Linq;
using System.Linq.Expressions;
namespace TestNamespace
{
class Test
{
static int Main()
{
Expression<Func<int[,]>> expr =
() => new int[2, 2] { { 1, 2 }, { 3, 4 } }; // CS0838
// try the following 2 lines instead
int[,] nums = new int[2, 2] { { 1, 2 }, { 3, 4 } };
Expression<Func<int[,]>> expr2 = () => nums;
return 1;
}
}
}