Optional output file in console application - make StreamWriter global
<p>I'm writing a console application which is looking up information about SSIS packages in SQL Server.  I have it working and writing to a .csv file.  I just added in the ability to pass command line switches for servername, foldername and outputfile.  If an output file is not specified, I'd just like to output to the console, which I'm already doing. </p>

<p>The way I've handled the file writing seems awkward, and is probably wrong. </p>

<p>In my main method I create a StreamWriter.  I need to write the entire output of the program to this file.  I explore folders under my specified folder by recursively calling a function. </p>

<p>I pass the StreamWriter object along in all calls - it is a parameter in functions which don't use it, so it can be passed to the one that does.  It seems like I should be able to make it a global variable, but I see that c# doesn't have globals and "if you are using a global, you are probably doing it wrong".</p>

<p>I'd planned on revisiting this issue eventually after plugging away at this little utility for a while, but I now have the problem that all the functions want the StreamWriter object - and if I make it optional, then it won't be there for the functions.  And it also seems c# doesn't do optional arguments.  </p>

<p>I'm sure you can tell I'm no c# expert and only dabble when I need to.  Thanks for your assistance.</p>
