As I understand it, Read() should work at each iteration, but alas not

 public static int[] fillArray() { int[] tmpMarks = new int[5]; for (int i = 0; i &lt tmpMarks.Length; i++) { Console.WriteLine("Put " + i + "element"); tmpMarks[i] = Console.Read(); } return tmpMarks; } 

Only three for some reason.

enter image description here

Thank you in advance :)

    2 answers 2

    The Read method reads one character from the input stream, including the carrethka and newline translation characters.

    Instead of this method, use the ReadLine method, and then convert the read string to an integer using one of the methods you desire.

    for example

     for (int i = 0; i &lt tmpMarks.Length; i++) { Console.Write("Put " + i + "element: "); int.TryParse(Console.ReadLine(), out tmpMarks[i]); } 

      Instead of Console.Read use Console.ReadLine followed by parsing the entered string into an int .
      For example, like this:

       public static int[] FillArray() { int[] tmpMarks = new int[5]; for (int i = 0; i < tmpMarks.Length; i++) { Console.WriteLine("Put " + i + " element"); while (!int.TryParse(Console.ReadLine(), out tmpMarks[i])) Console.WriteLine("Value cannot be parsed. Try again."); } return tmpMarks; }