Compilerfehler CS0636

Aktualisiert: November 2007

Fehlermeldung

Das FieldOffset-Attribut kann nur für Member des mit StructLayout(LayoutKind.Explicit) markierten Typs gesetzt werden.
The FieldOffset attribute can only be placed on members of types marked with the StructLayout(LayoutKind.Explicit)

Sie müssen das StructLayout(LayoutKind.Explicit)-Attribut für die Strukturdeklaration verwenden, wenn sie Member enthält, die mit dem FieldOffset-Attribut markiert sind. Weitere Informationen finden Sie unter FieldOffset.

Im folgenden Beispiel wird CS0636 generiert:

// 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 ()
   {
   }
}