Aggregate and ToArray function in System.Array not working

≡放荡痞女 提交于 2021-02-17 05:24:09

问题


I have this two errors:

'System.Array' does not contain a definition for 'Aggregate' and no extension method 'Aggregate' accepting a first argument of type 'System.Array' could be found (are you missing a using directive or an assembly reference?)

'System.Collections.Generic.IEnumerable<object[]>' does not contain a definition for 'ToArray' and no extension method 'ToArray' accepting a first argument of type 'System.Collections.Generic.IEnumerable<object[]>' could be found (are you missing a using directive or an assembly reference?)

Here is my code:

    /*
     * 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
    }

回答1:


You are missing

using System.Linq;

at the top of your file. Without this, the C# compiler doesn't know where the find the LINQ extensions you're trying to use.




回答2:


Add using System.Linq; at the top of .cs file.



来源:https://stackoverflow.com/questions/23660154/aggregate-and-toarray-function-in-system-array-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!