-2
我在C以下結構:如何在C#中的C結構寫的指針
typedef struct
{
int mode;
unsigned char *fs;//a pointer to sbyte[16]
unsigned char *flist;//a pointer to sbyte[128]
unsigned char *ival;//a pointer to sbyte[8]
unsigned char *ctx;//a pointer to sbyte[8]
int fin;
} mStruct;
,我需要它寫在C#。我試圖將其定義爲:
[StructLayout(LayoutKind.Sequential,Pack=1)]
public struct avGostParam
{
public int mode;//a mode
public IntPtr fs;// does char* converts to IntPtr?
public IntPtr flist;//does char* converts to IntPtr?
public IntPtr ival;//does char* converts to IntPtr?
public IntPtr ctx;//does char* converts to IntPtr?
public int fin;
}
但這是錯誤的方法。你能幫我翻譯成C#嗎?
使用指針,我相信你必須標記你的代碼爲'unsafe',並允許在項目屬性不安全的代碼。 –
不,'IntPtr'不需要'unsafe'(不要問爲什麼)...代碼是正確的。 – xanatos
爲什麼你需要指針?你只是想用一些數組作爲成員來聲明一個結構體?如果是這樣,請使用數組,而不是指針。 – adv12