How do you wait for input on the same Console.WriteLine() line?

后端 未结 2 1178
后悔当初
后悔当初 2020-12-30 18:37

I want to pose a question such as:

What is your name? Joe

How would I accomplish this using Console.WriteLine to also w

2条回答
  •  一生所求
    2020-12-30 19:31

    As Matt has said, use Console.Write. I would also recommend explicitly flushing the output, however - I believe WriteLine does this automatically, but I'd seen oddities when just using Console.Write and then waiting. So Matt's code becomes:

    Console.Write("What is your name? ");
    Console.Out.Flush();
    var name = Console.ReadLine();
    

提交回复
热议问题