我只是想交换指针中的地址。你知道只是尝试。 所以我得到了我可怜的代码:
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;
}
}
可怕的错误:
Error CS0269 Use of unassigned out parameter 'a' ConsoleApp1
Error CS0269 Use of unassigned out parameter 'b' ConsoleApp1
为什么?我不能在指针上使用关键字
out
吗?