【C#学习笔记】指针使用
using System; namespace ConsoleApplication2 { class Program { static void Main(string[] args) { int a = 5; unsafe { int* pa = &a; Console.WriteLine(*pa); } /************************************************************************/ int[] b = new int[10]; unsafe { fixed (int* pb = b) { for (int i = 0; i < 10;i++ ) { *(pb+i) = i; } } } foreach (int i in b) Console.Write(i); Console.WriteLine(); /************************************************************************/ unsafe { int* s = stackalloc int[5]; for (int i = 0; i < 5;i++ ) { *s=i; s++; } s = s - 5; for (int i = 0; i < 5;i++ ) { Console.Write(*(s+i)); } } Console.Read(); } } }