Is input on the same line as output in C #?

For example:

C: \> Enter a number: 60

If the output is "Enter the number:" and the input is "60".

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

EDIT: The problem I am facing is that when I print β€œEnter Number:”, it automatically starts a new line, so the user enters β€œ60” below (on the next line)

+6
c # console user-input
source share
2 answers

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

+18
source share

This will

 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 } 
+9
source share

All Articles