I am just trying to swap the address in the pointer. You know just try. SO I get my pathetic code:
unsafe class Test
{
static void Main()
{
int a = 1; int b = 2;
int* x = &a, y = &b;
Console.WriteLine($"{*x} and {*y}");
Swap(out x, out y);
Console.WriteLine($"{*x} and {*y}");
}
static void Swap(out int* a, out int* b)
{
long x = (long)a;
long y = (long)b;
x ^= y ^= x ^= y;
a = (int*)x; b = (int*)y;
}
}
Terrible error:
Error CS0269 Use of unassigned out parameter 'a' ConsoleApp1
Error CS0269 Use of unassigned out parameter 'b' ConsoleApp1
Why? Can't I using the keyword out
to the pointer?