Fares Ayyad

Fares Ayyad

  • NA
  • 235
  • 74k

Swapping elements in array using c#

Jan 20 2017 5:51 PM
Hello 
 
if  i have an array consist of 5 integers from 1 to 5 like this
  1. int [] numbers={1,2,3,4,5};  
So, i want to swap the last number (5) with the first number (1)
And
Swap the second number (2) with the fourth number (4)
 
So the number 3 (which is in the middle will stay in the middle with index of 2).
 
I tried to swap between the first and last number in this manner:
 
  1. numbers[4]=numbers[0];  
But i don't know if this is true, and what about the second swapping?
 

Answers (1)