i dont know whats wronng с этим кодом ... , когда он выполняется с помощью первого оператора if ... все хорошо , но если он пройдет второй, если ... есть ошибкаОшибка при разборе строки ввода до значения int в C#
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter a number and click enter, continue doing this process ");
Console.WriteLine("When you finish, just click enter without giving any input");
int i = 0;
int[] numbersArray;
List<int> numbersList = new List<int>();
while (true)
{
String numInput = Console.ReadLine();
numbersList.Add(Int32.Parse(numInput));
numbersArray = numbersList.ToArray();
if (i >= 1)
{
if (numbersArray[i] < numbersArray[i - 1])
{
Console.WriteLine("Your series is not going up!");
break;
Environment.Exit(0);
}
if (numbersArray[i] > numbersArray[i - 1])
{
if (numInput == "") {
break;
}
}
}
i++;
}
Console.WriteLine("You entered this series: ");
for (int j = 0; j < numbersArray.Length; j++)
{
Console.WriteLine(" " + numbersArray[j]);
}
Console.WriteLine("The length of the series youve entered is: " + numbersArray.Length);
}
}
Что ошибка? Также вы отметили python и c. – garfbradaz
Что это связано с Java, Android, Python или C? –
Вы не можете добраться до второго, если потому, что если вы дадите пустую строку Int32.Parse, она сработает. Вместо этого используйте Int32.TryParse – Steve