-4

Pretty much, I am trying to do the same thing as what python does:

x = input("Enter a number")

If I run this and enter "4", the console will look like

Enter a number4

In C# to my knowledge there is nothing like this and you have to do:

Console.WriteLine("Enter a number");
x = Console.ReadLine();

This makes it so that the prompt and the place where the user types in their input are on different console lines.

How do I make the prompt and the input on the same console line?

gunr2171
  • 16,104
  • 25
  • 61
  • 88
EldonHD
  • 7
  • 3
  • 2
    I'm *guessing* this is a duplicate of [How to take user input in the same line?](https://stackoverflow.com/questions/12556279/how-to-take-user-input-in-the-same-line) – Guy Incognito Apr 28 '23 at 18:50
  • 1
    @GuyIncognito I think has the right idea. There is ambiguity for "on the same line" between "on the same line of code", as in a single statement, and "on the same line _in the console_", which would use Write rather than WriteLine. – gunr2171 Apr 28 '23 at 18:52
  • 1
    Looking at the functionality of [python's input method](https://onlinegdb.com/ygusaR9rD), the OP means "on the same line of the console", rather than "in a single statement of code". I will edit the post to clarify that. – gunr2171 Apr 28 '23 at 19:01

1 Answers1

0

I don't know why would you want to do this, but you can try creating a method called "Input" and just call it in one line, as you do in python:

public static string Input(string message)
{
     Console.Write(message);
     return Console.ReadLine();
}

string x = Input("Enter a string:");
Lior v
  • 464
  • 3
  • 12