共用方式為


編譯器錯誤 CS0636

更新:2007 年 11 月

錯誤訊息

FieldOffset 屬性僅能置於標記為 StructLayout(LayoutKind.Explicit) 型別的成員上

如果結構宣告包含任何以 FieldOffset 屬性 (Attribute) 標記的成員,則必須使用 StructLayout(LayoutKind.Explicit) 屬性。如需詳細資訊,請參閱 FieldOffset

下列範例會產生 CS0636:

// CS0636.cs
using System;
using System.Runtime.InteropServices;

// To resolve the error, uncomment the following line:
// [StructLayout(LayoutKind.Explicit)]
struct Worksheet
{
   [FieldOffset(4)]public int i;   // CS0636 
}

public class MainClass
{
   public static void Main ()
   {
   }
}