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 can I do this in the c# array?
相关问题
- Sorting 3 numbers without branching [closed]
- How to toggle on Order in ReactJS
- Graphics.DrawImage() - Throws out of memory except
- PHP Recursively File Folder Scan Sorted by Modific
- Generic Generics in Managed C++
If you really only want to swap, you can use this method:
x and y are the indizies, that should be swapped.
If you want to swap with any type of array, then you can do it like this:
And you can call it like:
I just wrote something similar, so here is a version that
Enjoy :)
You could create an extension method that would work for any array
call this function and print elemet
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: