讓我來重述一下我的問題。在這段代碼中如何避免「while(true)」?
請考慮下面的代碼:
while (true)
{
Console.Write("Please enter something ");
userInput = Console.ReadLine();
if (string.IsNullOrEmpty(userInput))
{
break;
}
collection.Add(userInput);
}
怎樣纔可以改變,以避免使用while (true)
?
代碼的氣味是主觀的,標準太多選擇。你能否將這個問題重新定義爲可以得到客觀答案的東西? – hvd
是的,我會這樣做的。 – menteith