Console.Read () returns the ASCII value of the entered key. For example, if you type βAβ, you get a value of 65, which is the ASCII code for βAβ.
You will need to parse your string to an integer:
for (i = 0; i < 4; i++) { Console.WriteLine("Please enter test " + i); string input = Console.ReadLine(); int value; bool success = int.TryParse(input, out value); if (success) { test[i] = value } else {
Also note that arrays are indexed starting at 0 in C #, not 1, as your code suggests.
Alternatively, you can still use Console.Read (), which returns an integer representation of the entered character, confirm that the character is actually a number and convert from ASCII code to the corresponding number.
source share