Binary writer
Truth be told, I only vaguely remember why the technical editor wanted that check. I think it was because checking bw insures that Open() was called first and then Create() if the file has not been opened earlier in a write sequence. Since it is always a good idea to give resources, like file handles, back to the op system when you're done, calling WriteOneRecord() without opening the file for writing would throw an exception. If both members are non-null, it means that the file is open and can be used for writing. I think what the editor had in mind is a loop where, once the file is open, you can spin through a loop and write multiple records without having to open and close the file before each write.
Personally, I always prefer calling Open(), then WriteOneRecord(), and finally Close() to make sure I tie up the resources only as long as I need to. This also means that I tend to write only one record at a time, which is usually the case when you are adding or editing data.
For those of you trying to follow along, see page 374 and also 376.
__________________
Jack Purdum, Ph.D.
Author: Beginning C# 3.0: Introduction to Object Oriented Programming (and 14 other programming texts)
|