System.Array中的聚合和ToArray函数不起作用 [英] Aggregate and ToArray function in System.Array not working
问题描述
我有两个错误:
"System.Array"不包含"Aggregate"的定义,并且没有扩展方法'Aggregate'接受类型的第一个参数可以找到"System.Array"(您是否缺少using指令或程序集参考?)
'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 []>'不包含"ToArray"的定义,没有扩展方法"ToArray"接受类型的第一个参数可以找到"System.Collections.Generic.IEnumerable<对象[]>"(您是否缺少using指令或程序集引用?)
'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?)
这是我的代码:
/*
* 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
}
推荐答案
您丢失了
using System.Linq;
位于文件顶部.没有这个,C#编译器将不知道在哪里找到您要使用的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.
这篇关于System.Array中的聚合和ToArray函数不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!