Gilbot is correct as for the reason your code isn't working. But to answer your two other questions:
1: No, because if (output == null) returns true, the file wasn't opened, and hence need/can not be closed.
2: The brackets aren't necessary because only one function is run after the if statement. It might as well read "if (output == null) Display("Error opening file,");" on a single line. The linebreak is purely a matter of style and will be ignored by the compiler.
Quote from: Leon on Wed 21/01/2009 03:32:21
1: Shouldn't the output.Close(); be moved one bracket down? In this example the file gets opened, if nothing is written to it, it stays open.
2: Why aren't there brackets after the first if?
1: No, because if (output == null) returns true, the file wasn't opened, and hence need/can not be closed.
2: The brackets aren't necessary because only one function is run after the if statement. It might as well read "if (output == null) Display("Error opening file,");" on a single line. The linebreak is purely a matter of style and will be ignored by the compiler.