컴파일러 오류 CS0233

업데이트: 2007년 11월

오류 메시지

'identifier'에 미리 정의된 크기가 없으므로 sizeof는 안전하지 않은 컨텍스트에서만 사용할 수 있습니다. System.Runtime.InteropServices.Marshal.SizeOf를 사용하십시오.
'identifier' does not have a predefined size, therefore sizeof can only be used in an unsafe context (consider using 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));
   }
}