sizeof can only be used in an unsafe context (consider using System.Runtime.InteropServices.Marshal.SizeOf)
The sizeof operator can only be used in an unsafe block.
The following sample generates CS0233:
using System; using System.Runtime.InteropServices; [StructLayout(LayoutKind.Sequential)] public struct S { public int a; } public class MyClass { public static void Main() { S myS = new S(); Console.WriteLine(sizeof(myS)); // CS0233 // try the following line instead // Console.WriteLine(Marshal.SizeOf(myS)); } }