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
I just wrote something similar, so here is a version that
Enjoy :)
[TestClass]
public class MiscTests
{
[TestMethod]
public void TestSwap()
{
int[] sa = {3, 2};
sa.Swap(0, 1);
Assert.AreEqual(sa[0], 2);
Assert.AreEqual(sa[1], 3);
}
}
public static class SwapExtension
{
public static void Swap(this T[] a, int i1, int i2)
{
T t = a[i1];
a[i1] = a[i2];
a[i2] = t;
}
}