我不知道什麼是錯,但我一直得到相同的結果在控制檯:控制檯始終寫入相同的數字
111 118 101 114
我解決了這個問題,但現在我的控制檯不顯示我什麼。 我更新了我的代碼!
這是我的練習: 編寫一個程序並要求用戶連續輸入一個數字或輸入「退出」退出。數字列表可能包含重複項。顯示用戶輸入的唯一編號。
這是我的代碼:
while (true)
{
var numbers = new List<int>();
Console.WriteLine("write a number or type quit if you want to exit, if you want to finish write over: ");
var input = Console.ReadLine();
if (input.ToLower() == "quit")
{
break;
}
if (input.ToLower() == "over")
{
var uniq = new List<int>();
foreach (var other in numbers)
{
Convert.ToInt32(other);
if (!uniq.Contains(other))
{
uniq.Add(other);
Convert.ToInt32(other);
Console.WriteLine(other);
continue;
}
int cifre;
if (int.TryParse(input, out cifre))
{
numbers.Add(cifre);
}
else
{
Console.WriteLine("Invalid input, type 'quit', 'over' or a numeric value");
}
}
}
}
感謝幫助。
我想通了,我只是不得不復制該行:
變種數=新名單(); 到while循環的頂部,並且實際上使用了我在bignning中的所有相同的東西(因爲循環列表本身並不是sabving數字)。我將編輯我的代碼,以便您可以解救鍛鍊。
希望它可以幫助幫助
嘗試點擊生成,然後清理解決方案 – Taco2
你期望行'Convert.ToInt32(other);'做什麼? –
嘗試過,但它仍然相同 – Comp