Skip to main content
deleted 1 characters in body
Source Link
Chris
  • 2.9k
  • 22
  • 25

You can use an indexer propertiespropertie to access the array at a particular index. Unfortunately it needs to be defined on the struct itself rather than B, but this should provide what you're looking for:

[StructLayout(LayoutKind.Explicit, Size = 16)] public unsafe struct X { [FieldOffset(0)] private ushort a; [FieldOffset(2)] private fixed byte b[14]; public ushort A { get { return a; } } public byte this [int i] { get { byte b1; fixed (byte* b2 = b) { b1 = b2[i]; } return b1; } } }; 

You can use an indexer properties to access the array at a particular index. Unfortunately it needs to be defined on the struct itself rather than B, but this should provide what you're looking for:

[StructLayout(LayoutKind.Explicit, Size = 16)] public unsafe struct X { [FieldOffset(0)] private ushort a; [FieldOffset(2)] private fixed byte b[14]; public ushort A { get { return a; } } public byte this [int i] { get { byte b1; fixed (byte* b2 = b) { b1 = b2[i]; } return b1; } } }; 

You can use an indexer propertie to access the array at a particular index. Unfortunately it needs to be defined on the struct itself rather than B, but this should provide what you're looking for:

[StructLayout(LayoutKind.Explicit, Size = 16)] public unsafe struct X { [FieldOffset(0)] private ushort a; [FieldOffset(2)] private fixed byte b[14]; public ushort A { get { return a; } } public byte this [int i] { get { byte b1; fixed (byte* b2 = b) { b1 = b2[i]; } return b1; } } }; 
Source Link
Chris
  • 2.9k
  • 22
  • 25

You can use an indexer properties to access the array at a particular index. Unfortunately it needs to be defined on the struct itself rather than B, but this should provide what you're looking for:

[StructLayout(LayoutKind.Explicit, Size = 16)] public unsafe struct X { [FieldOffset(0)] private ushort a; [FieldOffset(2)] private fixed byte b[14]; public ushort A { get { return a; } } public byte this [int i] { get { byte b1; fixed (byte* b2 = b) { b1 = b2[i]; } return b1; } } };