System.Array 中的聚合和 ToArray 函数不起作用 [英] Aggregate and ToArray function in System.Array not working

查看:25
本文介绍了System.Array 中的聚合和 ToArray 函数不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个错误:

'System.Array' 不包含 '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' 不包含'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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆