構造体
[StructLayout( LayoutKind.Sequential, Pack = 1 )]
public struct Hoge
{
/// <summary> 6:コード</summary>
[MarshalAs( UnmanagedType.ByValArray, SizeConst = 6 )]
public byte[] Code;
}
変換関数
static public object ToStr( byte[] byteData, Type type )
{
GCHandle gch = GCHandle.Alloc( byteData, GCHandleType.Pinned );
object result = Marshal.PtrToStructure( gch.AddrOfPinnedObject(), type );
gch.Free();
return result;
}
使い方
Hoge dataL = (Hoge)ToStr( byData, typeof( Hoge ) );