6

For example:

C:\> Input a number: 60

Where the output would be "Input a number: " and the input would be "60".

How do I get these to be on the same line?

The problem is when I output "Input a number: ", it automatically starts a new line, so the user inputs "60" underneath (on the next line).

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Atomix
  • 2,440
  • 8
  • 36
  • 48

2 Answers2

20

Use System.Console.Write instead of System.Console.WriteLine

David Basarab
  • 72,212
  • 42
  • 129
  • 156
Esben Skov Pedersen
  • 4,437
  • 2
  • 32
  • 46
9

It would be

Console.Write("Input a number: ");

// It will return the entire string after the user hits enter
string theNumber = Console.ReadLine();

int number = 0;

if(int.TryParse(theNumber, out number))
{
  // Do something with the number
}
David Basarab
  • 72,212
  • 42
  • 129
  • 156