file i/o question

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm just learning C# so please excuse me if this is a dumb question.
In Delphi, you can declare, read, and write files of type TMyRecord,
where TMyRecord is a record structure that you have declared. I can't
find anything similar in C#. Can C# only read/write files that are
primitive types? If so, how do you save or read complex records
(structs) to/from files?
 
I do not think you can save a structure directly, but there is a concept of
serialization in which classes can be serialized into binary or XML format
and then written to the output stream. Take a look at the BinaryFormatter
class to get you started.
 
There is nothing like this as such, but there is nothing to prevent you from
declaring a structure or class with, say, a ToString() override or a
ToRecord() method that would turn its members into the exact record format
you want. Or you could make the class serializable and code the
serialization as desired. What you are describing in Delphi sounds like a
built in binary serialization method, so that's probably a starting point
for you. Shouldn't be tons of work to reproduce the functionality you
describe.

--Bob
 
Back
Top