0
我正在寫一個非常愚蠢的程序。第一個Console.ReadLine()立即返回
我不知道爲什麼下面的代碼將無法正常工作:
static void Main(string[] args){
<Some silly code>
Console.WriteLine("Please choose the lab you are working on:");
int choose = Console.Read();
<Some more silly code, including 1 Console.writeLine() call >
Console.WriteLine("Enter the DB server location");
string DBServer = Console.ReadLine();
Console.WriteLine("Enter the DB name");
string DBName = Console.ReadLine();
}
當我運行程序,它永遠不會等待第一的ReadLine聲明
string DBServer = Console.ReadLine();
它打印兩行立即
Enter the DB server location
Enter the DB name
然後讀取第二個ReadLine string DBName = Console.ReadLine();
當我檢查輸入表單用戶時,它確實讀取了第二個,但第一個字符串是空的。
任何想法?