編譯器錯誤 CS0208

更新:2007 年 11 月

錯誤訊息

無法取得 Managed 型別 ('type') 的位址、取得它的大小,或宣告指向它的指標

即使搭配 unsafe 關鍵字使用,也不允許取得 Managed 物件的位址、取得它的大小,或宣告指向 Managed 型別的指標。如需詳細資訊,請參閱 Unsafe 程式碼和指標 (C# 程式設計手冊)

範例

下列範例會產生 CS0208:

// CS0208.cs
// compile with: /unsafe

class S
{
    public int a = 98;
}

public class MyClass
{
    unsafe public static int Main()
    {
        S s = new S();  // S is managed
        S * s2 = &s;    // CS0208
        return 1;
    }
}