-1

Warning! Sorry, I'm bad english! Using a fixed array in struct:

[StructLayout(LayoutKind.Explicit, Size = 12)]
public unsafe struct union_reg
{
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 12)]
    [FieldOffset(0)]
    public fixed byte r[12]; 

    [FieldOffset(0)]
    public fixed UInt16 rp[6]; 
}

try create and get access to elements through array of pointers:

union_reg reg = new union_reg();
byte*[] r = new byte*[9] { &reg.r[rB], &reg.r[rC], &reg.r[rD], &reg.r[rE], &reg.r[rH], &reg.r[rL], &rhl, &reg.r[rA], &reg.r[6] };

If I declarete it in function, all fine, but if I try declarete it in class, I get error CS1666. Please help solve the problem!

const byte rB = 1;
const byte rC = 0;
const byte rD = 3;
const byte rE = 2;
const byte rH = 5;
const byte rL = 4;
const byte rA = 7;
const byte rF = 6;`

1 Answers1

-1

This error is clearly explained on msdn here.

You cannot have fixed types as fields/properties inside an unfixed class.

Blam
  • 2,888
  • 3
  • 25
  • 39