更新:2007 年 11 月
错误消息
“identifier”没有预定义大小,因此 sizeof 只能用于不安全的上下文中(请考虑使用 System.Runtime.InteropServices.Marshal.SizeOf)
示例
下面的示例生成 CS0233:
// CS0233.cs
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(S));   // CS0233
        // Try the following line instead:
        // Console.WriteLine(Marshal.SizeOf(myS));
   }
} | |