0

I want to write a Program which reads the user inputs in the same line. Such as

if we write

int x, y, z; 
x = Console.ReadLine();
y = Console.ReadLine();
z = Console.ReadLine();

when the user inputs the value of x and then press enter it creats a new line to read the value for y. Same happens when it's time for z. But I want it to do like this : When the user inputs a value for x and press Enter then it remains in the same line for reading another input which is the value for y and then in the same line for reading z

eg: If user inputs 4 for x, 5 for y and 6 for z

THE CODE OUTPUT SHOWS LIKE THIS FOR 3 DIFFERENT INTEGERS:
4
5
6

BUT I WANT IT TO BE LIKE THIS:
4  5  6

Note that I can easily read multiple values when Enter pressed once on the line as there plenty existing answers like Read numbers from the console given in a single line, separated by a space basically all doing String.Split, but it is different from what I want.

Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179
Acp Siam
  • 17
  • 6
  • 1
    ReadLine returns a string, you can split it and parse it into integers. – Jeremy Lakeman Dec 02 '20 at 06:05
  • 1
    https://learn.microsoft.com/en-us/dotnet/api/system.console.readkey?view=net-5.0#System_Console_ReadKey_System_Boolean_ - pass in `true`. – mjwills Dec 02 '20 at 06:07
  • @mjwills thanks for pointing that out. Half answer is https://stackoverflow.com/questions/29499132/c-sharp-console-how-to-readline-without-a-new-line-or-undo-a-n-or-a-vert – Alexei Levenkov Dec 02 '20 at 06:37
  • First of all, `int x = Console.ReadLine();` will not work. Second, what's the point? Just enter all 3 numbers then press enter? – SᴇM Dec 02 '20 at 06:40

0 Answers0