0

我有这两个错误:

“System.Array”不包含“Aggregate”的定义,并且找不到接受“System.Array”类型的第一个参数的扩展方法“Aggregate”(您是否缺少 using 指令或程序集引用?)

“System.Collections.Generic.IEnumerable<object[]>”不包含“ToArray”的定义,并且没有扩展方法“ToArray”接受“System.Collections.Generic.IEnumerable<object[]>”类型的第一个参数可以找到(您是否缺少 using 指令或程序集引用?)

这是我的代码:

    /*
     * Get all the possible permutations
     */
    public static IEnumerable<object[]> CartesianProduct(params object[][] inputs)
    {
        //ERROR: Function Aggregate is not recognized
        return inputs.Aggregate(
            (IEnumerable<object[]>)new object[][] { new object[0] },
            (soFar, input) =>
                from prevProductItem in soFar
                from item in input
                select prevProductItem.Concat(new object[] { item }).ToArray());
    }

    public void test()
    {
            //Get all the posible permutations between parents values.
            var cartesianProduct = CartesianProduct(parentsValues);
            object[][] producto = cartesianProduct.ToArray();
            //ERROR: Function ToArray is not recognized
    }
4

2 回答 2

6

你不见了

using System.Linq;

在文件的顶部。没有这个,C# 编译器不知道在哪里可以找到您尝试使用的 LINQ 扩展。

于 2014-05-14T16:25:30.320 回答
0

using System.Linq;在 .cs 文件的顶部添加。

于 2014-05-14T16:26:53.883 回答