J'essaye d'obtenir une chaîne de la console et de mettre tous les éléments dans un tableau int. Il se produit une erreur indiquant que mon entrée était dans un format incorrect. J'essaie avec "1 1 3 1 2 2 0 0" et j'ai besoin de ceux-ci comme valeurs int et plus tard effectuer quelques calculs avec eux.String array to Int array
Voici ma tentative:
class Program
{
static void Main()
{
string first = Console.ReadLine();
string[] First = new string[first.Length];
for (int i = 0; i < first.Length; i++)
{
First[i] += first[i];
}
int[] Arr = new int[First.Length];//int array for string console values
for (int i = 0; i < First.Length; i++)//goes true all elements and converts them into Int32
{
Arr[i] = Convert.ToInt32(First[i].ToString());
}
for (int i = 0; i < Arr.Length; i++)//print array to see what happened
{
Console.WriteLine(Arr[i]);
}
}
}
vous devez assigner à une variable 'String []' dans la deuxième ligne. –