I'm trying to get a string from memory using StrucLayout and FieldOffset
But I'm having a lot of trouble understanding how byte works.
Here is my code ATM :
[StructLayout(LayoutKind.Explicit)]
public unsafe struct InfoDetails
{
[FieldOffset(0x14)]
public fixed sbyte Name[50];
public string getName
{
get
{
fixed (sbyte* namePtr = Name)
{
return new string(namePtr);
}
}
}
}
This code returns : T. Expected result is TEZ.
Any advices on why I'm doing it wrong ? Thanks
You could change the signature to:
Note how I changed
sbytetocharand I halved the size of the buffer (becausesizeof(char)== 2)Or you could even, more simply add a single cast to
char*:without changing anything else.