效果
代码
int[] array = { 1, 3, -1, 5, -2 };
int[] newarray = new int[array.Length];
for (int i = 0; i < array.Length ; i++)
{
if (array[i] < 0)
{
newarray[array.Length - i-1] = 0;
}
else
{
newarray[array.Length - i-1] = array[i];
}
}
Console.WriteLine("原数组为:");
foreach (var item in array )
{
Console.Write(item +"\t");
}
Console.WriteLine("");
Console.WriteLine("逆序并处理后的数组为:");
foreach (var item in newarray)
{
Console.Write(item + "\t");
}
Console.ReadKey();