using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; namespace ConsoleApplication1 { struct CoOrds { public int x; public int y; } class Program { static void Main(string[] args) { Console.WriteLine("************************************************************"); CoOrds home; unsafe { CoOrds* p = &home; p->x = 25; p->y = 12; System.Console.WriteLine("The coordinates are: x={0}, y={1}", p->x, p->y); Console.ReadKey(); } } } }
编译时需要将项目属性中生成的允许不安全代码勾上。