日期:2014-05-18  浏览次数:21145 次

C# float[]如何变成IntPtr
如题,在C#中,怎么将loat[]变成IntPtr?
请各位大侠指教。


------解决方案--------------------
忘记了 以前用过 帮你顶了
------解决方案--------------------
 
using System.Runtime.InteropServices
Marshal.StructureToPtr 方法
------解决方案--------------------
Marshal.Copy
------解决方案--------------------
n 是 sizeof(float) * m.Length,复制用 Marshal.Copy
C# code
float[] m = new float[6];
int size = sizeof(float) * m.Length;
IntPtr ptr = Marshal.AllocHGlobal(size);
Marshal.Copy(m, 0, ptr, m.Length);

------解决方案--------------------
float[]a={0.231,0.154};
IntPtr p;
Marshal.Copy(a,0,p,a.Length);
------解决方案--------------------
C# code
            float[] f = new float[] {1f,2f,3f};
            unsafe
            {
                fixed (float* pf = f)
                {
                    IntPtr address = new IntPtr(pf);
                }
            }

------解决方案--------------------
float[] f = new float[10];
IntPtr[] intptr = f.Select(t => new IntPtr(Convert.ToInt32(t))).ToArray();