
Signature
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com
> 1. Should I still use structures or am I better off accepting any
> additional overhead of using class objects to represent each record?
I don't think that there's any difference at the time of writing them to
disk. You should choose structures or classes based on how you are going to
use them in your program, not on the need of writing to disk.
> 2. What is the best way to write structures or classes to disk?
My favourite way is to serialize them. Mark the class or struct with a
[Serializable] attribute and then use a BinaryFormatter to write the
contents to a FileStream.
> 3. What is the best way to write a collection of structures or classes to
> disk?
Make sure that all the objects in the collection are [Serializable] and
apply the preceding method.
> 4. How come most of the file and try...catch examples I've found seem
> absolutely retarded to me? For example, most leave the line that opens the
> file (the line most likely to fail) before try, outside of the try block?
> What is the point of that?
Maybe they do that because they are writing a Finally block that is
closing the file, so they only want it to execute if the open succeeded. If
it fails, it is caught at a higher level (a try...catch in the routine that
made the call to the ne that is opening the file). I'm not saying that I
like this, just trying to find a logic for the examples that are written in
the way you mention.