public static TestStruct FromBinaryReaderBlock(BinaryReader br)
{ //Read byte array byte[] buff = br.ReadBytes(Marshal.SizeOf(typeof(TestStruct)));
//Make sure that the Garbage Collector doesn't move our buffer
GCHandle handle = GCHandle.Alloc(buff, GCHandleType.Pinned);
//Marshal the bytes TestStruct s = (TestStruct)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(TestStruct));
handle.Free();//Give control of the buffer back to the GC
return s;
}
想用这段程序,但结构是直接指定的,如果结构是个变量应该怎么写?
慕后森