简体   繁体   中英

.NET Core: Array class does not contain definition for ConvertAll

I'm currently following https://www.hackerrank.com/challenges/diagonal-difference for my C# learning process. I copy and paste the given code for C#. Here I need to convert String array to Int Array. Example code uses Array.ConvertAll(a_temp,Int32.Parse) to do that. But in my Visual Studio Community 2017 IDE it gives error for ConverAll method.

'Array' does not contain definition for ConvertAll

But when I refered

我的IDE视图

As you can see my IDE does not give suggestion for ConvertAll Method. I'm not sure this is a beginners dumb mistake. So I'll add my code in IDE here (Almost same code in 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);
        }
    }
}

Looks like you are working in .NET Core project and there is not such method in .NET Core yet. You could either create new project with Full .NET Framework 4.6.x or use Enumerable Extensions to convert your array:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM