0
嗨我寫了一個方法/數組我試圖讓我的代碼交換索引中的第二個數字和倒數第二個數字,但唯一交換的數字是我的第二個數字,我的最後,如果你能幫助一個新手,我會非常感謝你。方法與數組,索引中的交換號碼
static void Main(string[] args)
{
Console.WriteLine("\n=====================\n");
DisplayArray(A);
Console.WriteLine("\nSwapping Second and Second to last Number");
SwapSecAndSecLast(A);
DisplayArray(A);
Console.ReadLine();
}
static void SwapSecAndSecLast(int[] array)
{
int temp = array[1];
array[1] = array[array.Length - 1];
array[array.Length - 1] = temp;
}
static void DisplayArray(int[] array)
{
Console.WriteLine("\n=====================\n");
for (int i = 0; i < array.Length; i++)
{
Console.Write("{0} ",array[i]);
}
Console.WriteLine("\n=====================\n");
}
擊敗我吧。 :)這是正確的答案。 – Jeremy
Oh dang清晨,我告訴你我的大腦沒有運行大聲笑 – TheBoringGuy