05-26-2012, 12:57 PM
Or you can return by reference:
public void swap(ref int a, ref int b)
{
int c = a;
a = b;
b = c;
}
//...
int a = 0, b = 1;
swap(ref a,ref b);
//...
Since in C# every Type is inherited from the base object class you could just return an array of objects:
public object[] Swap(int a, int b)
{
return new object[] { b, a };
}
//...
int a = 0, b = 1;
object[] data = Swap(a, b);
a = (int)data[0];
b = (int)data[1];
//...

