问题
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