I've seen several related topics on SO and other forums, but haven't found a workable answer to my question.
Here's my code:
[StructLayout(LayoutKind.Explicit, Size = 128)]
internal unsafe struct Frame
{
[FieldOffset(0)]
public fixed byte Bytes[128];
[FieldOffset(0)]
public long Low;
[FieldOffset(128 - sizeof(long))]
public long High;
}
unsafe private void button32_Click(object sender, EventArgs e)
{
Frame frame;
// ERROR: Error 15 You cannot use the fixed statement to take the address of an already fixed expression
fixed (byte* ptr = frame.Bytes)
{
}
// ERROR
Console.Write(System.Text.Encoding.ASCII.GetString(frame.Bytes, 0, 128));
frame.Low = 1234;
//Console.Write(System.Text.Encoding.ASCII.GetString(frame.Bytes));
frame.High = 5678;
//Console.Write(System.Text.Encoding.ASCII.GetString(frame.Bytes));
}
new string((sbyte*) frame.Bytes)should work if you are using ASCII only (or perhaps the overload takingstartandlength).any value? Using something else than ASCII?