Home

Incorrect result for fixed buffer

With this code:

var data = 1065353216;
var foo = Unsafe.AsRef<Foo>(&data);
Console.WriteLine(foo);

[StructLayout(LayoutKind.Explicit)]
struct Foo
{
    [FieldOffset(0)] public int Int;
    [FieldOffset(0)] public float Float;
    [FieldOffset(0)] public unsafe fixed byte Bytes[4];
}

LinqPad cannot correctly display the fixed buffer field:

Comments

Sign In or Register to comment.