Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
'identifier' does not have a predefined size, therefore sizeof can only be used in an unsafe context
Without unsafe context, the sizeof operator can only be used for types whose size is a compile-time constant. If you are getting this error, use an unsafe context.
The following example generates 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 instead:
// unsafe
// {
// Console.WriteLine(sizeof(S));
// }
}
}
.NET feedback
.NET is an open source project. Select a link to provide feedback: