System.Array中的Aggregate和ToArray函数不起作用

ang*_*res 0 .net c# ienumerable system.array .net-4.5

我有这两个错误:

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

'System.Collections.Generic.IEnumerable <object []>'不包含'ToArray'的定义,也没有扩展方法'ToArray'接受类型'System.Collections.Generic.IEnumerable <object []>'的第一个参数可以找到(你错过了使用指令或程序集引用吗?)

这是我的代码:

    /*
     * 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
    }
Run Code Online (Sandbox Code Playgroud)

Tim*_* S. 6

你错过了

using System.Linq;
Run Code Online (Sandbox Code Playgroud)

在您的文件的顶部.如果没有这个,C#编译器就不知道在哪里找到你想要使用的LINQ扩展.