2012年3月29日

C# byte[] 获取数组的IntPtr

摘要: 有几种方法可以访问与字节数组相对应的 IntPtr。第一种是使用不安全的代码块来访问直接指向字节数组的指针。//C#unsafe{byte[] test = new byte[5];fixed (byte* p = &test[0]){*p = 0xff;}}也可以使用 GCHandle 来获得对象。//C#using System.Runtime.InteropServices;byte[] test = new byte[5];GCHandle hObject = GCHandle.Alloc(test, GCHandleType.Pinned);IntPtr pObject = 阅读全文

posted @ 2012-03-29 16:47 Juneson 阅读(5432) 评论(1) 推荐(0) 编辑

导航