现在我从文件中读取到一串Byte[]数组,里面的类容是按格式写的,比如前面的字节是一个文件头,而这个文件头是我定好的struct。
例如:
typedef stuct FileHead
{
char a[20];
char b[40];
int c;
int d
}FileHead;我如何从前面连续的字符中获取到这个结构体。
文件是用C写的,在C中只需要利用指针做个强转就可以了, 问C#下如何实现。
谢了!!!
例如:
typedef stuct FileHead
{
char a[20];
char b[40];
int c;
int d
}FileHead;我如何从前面连续的字符中获取到这个结构体。
文件是用C写的,在C中只需要利用指针做个强转就可以了, 问C#下如何实现。
谢了!!!
BinaryReader br=new BinaryReader(stream);
FileHead fh=new FileHead();
fh.a=br.ReadChars(20);
fh.b=br.ReadChars(40);
fh.c=br.ReadInt32();
fh.d=br.ReadInt32();
//结构体定义如下
stuct FileHead
{
public char[] a;
public char[] b
public int c;
public int d
}FileHead;
像C里面的可以一步到位的
FileHead stFileHead = *(FileHead*)br;