ご意見ありがとうございます。私はまだ範囲外の例外を取得しています。私はデバッグしていますが、なぜ例外が発生しているのか理解できません。 intが特定の他のintよりも高い場合は動作するはずです。それは長さと関係がありますか?カウント?データの有効性を確認したC#リスト数
私はif文他に最初の検証を持ついくつかの問題を抱えている
do
{
Console.Write("Input the element that you want to exclude from the list: ");
result = int.TryParse(Console.ReadLine(), out delSelection);
tempInputDelInt = (int)(tempList[delSelection]);
tempInputDelStr = Convert.ToString(tempInputDelInt);
if (result == true && tempInputDelInt >= 0 && tempInputDelInt < tempList.Count)
{
tempList.RemoveAt(delSelection);
Console.WriteLine("\nYou've deleted the temperature " + tempInputDelStr + " from index " + delSelection);
success = false;
Console.ReadKey(true);
Console.Clear();
}
else if (result == true && tempInputDelInt >= tempList.Count || tempInputDelInt < 0)
{
Console.WriteLine("You've input a number that's outside the list. Input a digit between 0 and " + (tempList.Count - 1) + ".\n");
success = true;
Console.ReadKey(true);
}
else if (result == false)
{
Console.WriteLine("\nYou didn't input a digit, try again!\n");
success = true;
Console.ReadKey(true);
}
} while (success);
success = false;
更新されたコード。配列の外側の値が入力されたときにケースをキャッチしたいが、私はそれを管理しない。
私はarray.Lengthと実質的に同じプログラムを成功させました。
array.Listとlist.Countに違いはありますか?それは問題ですか?
ご協力いただきありがとうございます。
do
{
Console.Write("Input the element that you want to exclude from the list: ");
result = int.TryParse(Console.ReadLine(), out delSelection);
tempInputDel = Convert.ToString(tempList[delSelection]);
if (result == true && delSelection >= 0 && delSelection < tempList.Count)
{
tempList.RemoveAt(delSelection);
Console.WriteLine("\nYou've deleted the temperature " + tempInputDel + " from index " + delSelection);
Console.ReadKey(true);
Console.Clear();
}
else if (result == true && delSelection >= tempList.Count || delSelection < 0)
{
Console.WriteLine("You've input a number that's outside the list. Input a digit between 0 and " + (tempList.Count - 1) + ".\n");
}
else if (result == false)
{
Console.WriteLine("\nYou didn't input a digit, try again!");
Console.ReadKey(true);
}
} while (result == false);
何が問題になりますか? –