c# - .NET 核心 : Array class does not contain definition for ConvertAll

标签 c# .net arrays visual-studio

我目前正在关注 https://www.hackerrank.com/challenges/diagonal-difference对于我的C#学习过程。我复制并粘贴了 C# 的给定代码。这里我需要将 String 数组转换为 Int 数组。示例代码使用 Array.ConvertAll(a_temp,Int32.Parse) 来执行此操作。但是在我的 Visual Studio Community 2017 IDE 中,它给出了 ConverAll 方法的错误。

'Array' does not contain definition for ConvertAll

但是当我提到

My IDE views

如您所见,我的 IDE 没有为 ConvertAll 方法提供建议。我不确定这是初学者的愚蠢错误。所以我将在此处的 IDE 中添加我的代码(在 hackerrank 中几乎是相同的代码)

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
class Solution
{
    static void Main(String[] args)
    {
        int n = Convert.ToInt32(Console.ReadLine());
        int[][] a = new int[n][];
        for (int a_i = 0; a_i < n; a_i++)
        {
            string[] a_temp = Console.ReadLine().Split(' ');
            a[a_i] = Array.ConvertAll(a_temp, Int32.Parse);
        }
    }
}

最佳答案

看起来你在 .NET Core 项目中工作,而 .NET Core 中还没有这样的方法。您可以使用 Full .NET Framework 4.6.x 创建新项目或使用 Enumerable Extensions 来转换您的数组:

string[] a_temp = Console.ReadLine().Split(' ');
a[a_i] = a_temp.Select(s => Int32.Parse(s)).ToArray();

关于c# - .NET 核心 : Array class does not contain definition for ConvertAll,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43534955/

相关文章:

c# - 如何获取outlook联系人的头像?

c# - HttpWebRequest keep alive - .net 如何重用连接?

c# - URL 中的隐藏参数

c# - 如何在下拉列表中添加表字段的2列值

javascript - 使用 Javascript 数组对数字进行阶乘

c# - 我们可以为两个事件设置相同的委托(delegate)吗

c# - 正则表达式用于删除逗号周围的空格(引用时除外)

c# - 如何在 C# 中将字符串的内容复制到剪贴板?

ios - for 语句循环未按预期工作

c - C 中的数组和枚举有什么区别?