char[] c=new char[2];
c[0]='1';
c[1]='2';
unsafe{
void *p;
fixed (char *pc=&c[0])
p=(void *)pc;
IntPtr ptr=new IntPtr(p);
}
c[0]='1';
c[1]='2';
unsafe{
void *p;
fixed (char *pc=&c[0])
p=(void *)pc;
IntPtr ptr=new IntPtr(p);
}
而且是一个很难使用的东西。我一般只用char,而用string代替char[]。
如果调用非托管方法,那么可以将char*用string或IntPtr代替,
C#会进行默认封送(参见MarshalAs)。这样在封送过程中就把IntPtr或
String转换为char*。反过来也一样。