編譯器錯誤 CS0233
更新:2007 年 11 月
錯誤訊息
'identifier' 沒有預先定義的大小,因此 sizeof 只能使用於 unsafe 內容 (可考慮使用 System.Runtime.InteropServices.Marshal.SizeOf)
sizeof 運算子只能用於編譯時期常數的型別。如果您遇到這個錯誤,請確定識別項的大小是否可以在編譯時期決定。如果不行,則使用 SizeOf 來取代 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));
}
}