tags:

views:

72

answers:

2

I would like to fetch n bytes from specific place in a file into my specific data structure (a struct).

The old C - application (which we are porting) uses fseek() and fread().

Is where a comparable solution in C#/.Net, without using the Win32-API?

+5  A: 

I'd use the FileStream class, and then the Seek + Read methods and Position property.

Rudu
To add, wrap a `BinaryReader`/`BinaryWriter` around that stream for the conversion between primitive types and byte arrays.
Mark H
The performance is really important. I would like to read a whole struct like in the old c++ application. For example
Adesit
The performance is really important. I would like to read a whole struct like in the old c++ application. Like this:fread( My DataRecord contains variables of different primitive types and also 'subrecords'. I have a problem with performance: in the c- application reading a record is one IO operation.
Adesit
I think, using Win32 APi is my only option.
Adesit
A: 

I would suggest since you are porting a C application to a C# application that you store data in objects, not structs, unless you really care about overhead performance.

Bernard