LoginSignup
3
2

More than 5 years have passed since last update.

byte列をstructにする

Last updated at Posted at 2013-02-11
構造体
[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 ) );
3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2