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
https://msdn.microsoft.com/en-us/library/system.array(v=vs.110).aspx
it says it Exists(ConvertAll) in System namespace.
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With