How can I swap two values of an array in c#?

后端 未结 6 514
情话喂你
情话喂你 2021-01-17 06:45

I have an array of int containing some values starting from index 0. I want to swap two values for example value of index 0 should be swapped with the value of index 1. How

6条回答
  •  南笙
    南笙 (楼主)
    2021-01-17 07:19

    swap only two values only once or want to do the same for the entire array.

    Assuming that you only want to swap only two only once and is of type integer, then you can try this:

        int temp=0;
        temp=arr[0];
        arr[0]=arr[1];
        arr[1]=temp;
    

提交回复
热议问题