[.net] C# struct to byte[]

Started by
3 comments, last by MTclip 17 years, 8 months ago
hey guys, Im tring to a struct of mine so i can stream in data from a binary file... heres what i got

            
BinaryReader fin = new BinaryReader( File.OpenRead( file ));            
fin.Read((byte[])fileHeader, 0, Marshal.SizeOf(fileHeader));
// were fileHeader is an instance of the struct

the error is that it cannot convert the struct to a byte[].. any help here would be great thanks
Advertisement
You probably need a Binary Formatter to deserialize the data. But that will only work if the data stored in the file is serialized by the same formatter.


http://msdn2.microsoft.com/en-us/library/system.runtime.serialization.formatters.binary.binaryformatter.aspx

Greetings.

EDIT: This is probably not what you need.

[Edited by - Limitz on August 24, 2006 9:38:19 PM]
That was certainly interesting, but its not really what im looking for... at least I dont want to do that to solve this issue ;p

thanks anyhow
I found a site that describes a few solutions to your problem:

http://dotnetjunkies.com/Article/DF6E5BE5-BCB6-43BB-BEE4-1013A2E3D085.dcik

Forget my previous post (it is very late here :) )
Greetings.

cool thanks..

This topic is closed to new replies.

Advertisement