c# 指针

指针变量声明:
例:
int* p1, p2, p3;


public static unsafe void swap(int a,int b)
{
int temp;
temp = a;
a = b;
b = a;
}


public static unsafe void swapP(int* pa,int* pb)
{
int temp = *pa;
*pa = *pb;
*pb = temp;
}
private static unsafe void Main(string[] args)
{
int a = 10, b = 20;

Console.WriteLine("a:" + a + ",b:" + b);


swap(a, b);

Console.WriteLine("after swap:a:" + a + ",b:" + b);


int* pa = &a, pb = &b;

swapP(pa, pb);

Console.WriteLine("after swapP:a:" + a + ",b:" + b);

Console.ReadKey();
}



a:10,b:20
after swap:a:10,b:20
after swapP:a:20,b:10

posted @ 2020-07-19 13:32  流星曳尾  阅读(367)  评论(0编辑  收藏  举报