C# equivalent of fread/fwrite with data structures

  • Thread starter Thread starter Eric
  • Start date Start date
E

Eric

I want to seek in a file to retrieve or write fixed length data structures.
Serialization is great, but I don't want to read in the entire file just to
retrieve one or two "records."

Has anyone mastered something similar using a managed alternative? If not,
can anyone point me to a good tutorial on this using unsafe code?

I have been able to accomplish this using managed code, but it looks pretty
ugly and requires a number of steps.

This brings me to one more sort of related question.
Is there any way I can represent the following attribute:

[StructLayout(LayoutKind.Sequential, Pack = 1)]

.... using code and not attributes? I don't really like attribute voodoo. I
can figure out how to translate most attributes into code, but not this.
 
Back
Top