I am still learning C#. I come from a Delphi and C past.

I am used to being to create flat data files of of records. Example:

// Sample Delphi code...

type
  SectorRecord = Record
  iIdx    : integer;
  iCoordX : integer;
  iCoordY : integer;
  sName   : String[60];
end;

  .....

myFile : File of SectorRecord;
sr     : SectorRecord;

AssignFile(myFile,'someFileName.DAT');
Reset(myFile);
Read(myFile,sr);
CloseFile(myFile);

Is there just nothing like this in C#?

Everything I look up concerning file access in C# points me back to text files I have to parse through, or creating a database (and all the support coding that goes along with that).

Am I just not understanding the terminology and not looking up the right word for this type of file?

Thanks in advance.

Recommended Answers

All 5 Replies

Perhaps you should take a look at XML files.
You can both import and export them into a datatable for manipulation.

Zinderin, take a look at the binary reader and binary writer. That's the closest you'll get to being able to achieve what you want.

Zinderin, take a look at the binary reader and binary writer. That's the closest you'll get to being able to achieve what you want.

Thanks guys ... both of you. :)

XML just doesn't do it if you have 100,000s on 100,000s records. Especially with small records (the XML overhead becomes bigger than the actual data). And I don't even want to get into the "deer in the headlights" look you get from a small business when you start talking about changing their data formats. They've already been through the pain ... they don't want to change anything.

And the binaryReader/Writer just seems insanely clumsy to me (I did continue to search after posting my question here and found the binaryReader/Writer). Granted its likely just my inexperience with the language.

I guess its back to C for this stuff. Or waiting til I understand C# well enough to build an API in C and link it in to my C# code. :(

It is just crazy to me that they don't support this. Especially given how static C# is, and considering its ancestry.

Thanks again.

You can actually serialise objects into Binary. Then write them to your binary file.

It's pretty straight forward and with a little helper/base class is actually quite quick and easy to understand. (About 4 lines of code each way)

You can actually serialise objects into Binary. Then write them to your binary file.

It's pretty straight forward and with a little helper/base class is actually quite quick and easy to understand. (About 4 lines of code each way)

Thanks Ketsuekiame ... clearly it is my inexperience then. I have more to learn. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.