首先,这个问题不是
System.Console.Write instead of System.Console.WriteLine
....
<Console.Write();>: <Console.ReadLine>
我认为这最能解释我的问题,
我有......
string stringone = Console.ReadLine();
string stringtwo = Console.ReadLine();
....
//what it does
<Console.ReadLine> (after enter is pressed moves to next line)
<Console.ReadLine>
//what I want
<Console.ReadLine> <Console.ReadLine>
如果可能的话,任何替代/解决方案或理由都是非常重要的。
答案 0 :(得分:3)
using System;
class Test
{
static void Main()
{
//split input by spaces into array
string[] name = Console.ReadLine().Split();
Console.WriteLine("First name: " + name[0]);
Console.WriteLine("Last Name: " + name[1]);
}
}
答案 1 :(得分:2)
使用SetCursorPosition。
using System;
class Program
{
public static void Main(string[] args)
{
string question1 = "What is your name? ";
string question2 = "How old are you? ";
// first question
Console.Write(question1);
string name = Console.ReadLine();
// second question
Console.SetCursorPosition(question1.Length + name.Length + 1, 0);
Console.Write(question2);
string age = Console.ReadLine();
// print output
Console.WriteLine("Hello {0}, your age is {1}", name, age);
Console.Write("Press any key to continue . . . ");
Console.ReadKey(true);
}
}
https://msdn.microsoft.com/en-us/library/system.console.setcursorposition(v=vs.110).aspx
答案 2 :(得分:1)
这应该可以解决问题:
string one = Console.ReadLine();
Console.SetCursorPosition(one.Length + 1, 0);
string two = Console.ReadLine();
Console.SetCursorPosition(one.Length + two.Length + 2, 0);