Have you read the documentation?
The Read method blocks its return while you type input characters;
it terminates when you press the Enter key. Pressing Enter appends a
platform-dependent line termination sequence to your input (for example,
Windows appends a carriage return-linefeed sequence). Subsequent calls to the
Read method retrieve your input one character at a time. After the final
character is retrieved, Read blocks its return again and the cycle repeats.
Note that you will not get a property value of -1 unless you perform one of the
following actions: simultaneously press the Control modifier key and Z console
key (Ctrl+Z), which signals the end-of-file condition; press an equivalent key
that signals the end-of-file condition, such as the F6 function key in Windows;
or redirect the input stream to a source, such as a text file, that has an actual
end-of-file character.
The ReadLine method, or the KeyAvailable property and ReadKey method are
preferable to using the Read method.
If I execute this code:
Console.Write("? ") ;
int input = Console.Read() ;
Console.WriteLine("You entered {0}.", input ) ;
Console.WriteLine( "{0} is the decimal code point for the character whose glyph is '{1}.'" , input , (char)input ) ;
And, if I, at the ? prompt, enter the characters 123 followed by the return key:
? 123<return>
I'll see this output:
You entered 49.
49 is the decimal code point for the character whose glyph is '1'.
[Note that in Windows, you can generate a '1' at the command prompt by holding down the <ALT> key, typing '0049and releasing the` key.]
Assuming that the intent is for the user to specify a number of values to be entered and to then prompt them for that many input values, you want code that looks something like this:
static void Main()
{
int n = ReadIntegerFromConsole( "How many values do you want to enter?" ) ;
int[] values = new int[n] ;
for ( int i = 0 ; i < values.Length ; ++i )
{
string prompt = string.Format( "{0}/{1}?" , i , n ) ;
values[i] = ReadIntegerFromConsole(prompt) ;
}
Console.WriteLine( "You entered: {0}" , string.Join(", ",values) ) ;
return ;
}
static int ReadIntegerFromConsole( string prompt )
{
int value ;
bool isValid ;
do
{
Console.Write( prompt) ;
Console.Write( ' ' );
string text = Console.ReadLine() ;
isValid = int.TryParse(text, out value ) ;
prompt = "That's not an integer. Try again:" ;
} while (!isValid) ;
return value ;
}
Console.ReadLine()instead ofConsole.Read().