The program should work like this:
Asks the user for the length of the array, the user enters. Asks what type of array the user needs (int or string), the user chooses. Next, an array is created with the desired data type, and a length that it indicated above. And then the program simply writes Finish!
What is the incomprehensible error of the program? For some reason, after creating the array, it again asks for its length ... And only then writes Finish! Why it happens? It seems everything wrote correctly ...
Here is the code:
using System; namespace Launcher { class Program { public static void Main(string[] args) { dlin_ARRAY(); tip_ARRAY(); Console.WriteLine("Finish!"); Console.Read(); } public static int dlin_ARRAY() { Console.WriteLine("Введи длину массива"); Console.WriteLine(">>>"); int userinput_dlin_ARRAY = int.Parse(Console.ReadLine()); Console.WriteLine("<<<"); return userinput_dlin_ARRAY; } public static void tip_ARRAY() { Console.WriteLine("Введи цифру типа массива, который тебе нужен"); Console.WriteLine("1) Integer"); Console.WriteLine("2) Stringer"); bool isTrue = true; while (isTrue) { Console.WriteLine(">>>"); int userinput_tip_ARRAY = int.Parse(Console.ReadLine()); Console.WriteLine("<<<"); if (userinput_tip_ARRAY == 1) { int[] array = new int[dlin_ARRAY()]; } else if (userinput_tip_ARRAY == 2) { string[] array = new string[dlin_ARRAY()]; } else { Console.WriteLine("Не верно, введи 1 или 2"); continue; } isTrue = false; } } } }
dlin_ARRAY()method into the following method, in which you call the method again:new int/string[dlin_ARRAY()]. So there are no bugs. The program does exactly what you wrote - Kir_Antipovdlin_ARRAY()method, and understand why it asks length many times - tym32167