Pregunta

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
    }
¿Fue útil?

Solución

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.

Otros consejos

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

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top