为什么删除数组的某个元素,总是提示索引超出数组界限 string[] furniture = new string[] { "桌子", "椅子", "床", "沙发" };
int length = furniture.Length;
Console.WriteLine("the length of the array furniture is {0}", length);
Console.WriteLine("please input the index of what you delete:");
int index = Convert.ToInt16(Console.ReadLine());
if (index < 0 && index > 3)
{
Console.WriteLine("the index you input is wrong");
}
else
{
for (int i = index; i < length; i++)
{
furniture[i] = furniture[i + 1];//总是提示索引超出数组界限
}
}
foreach (string m in furniture)
{
Console.WriteLine("after delete the index is {0}", m);
}
Console.ReadLine();