Why are they "ugly"?
They are there for a good reason - to ensure that if you have opened a file, that you close it properly.
You could move the code into a method, if it upsets you that much, but I would leave it pretty much as it is, possibly just changing
if (FileOutOpen)
{
if (FileOut != null)
FileOut.Close();
}
to
if (FileOutOpen && FileOut != null)
{
FileOut.Close();
}
And please, be consistent with your braces!
If you need braces in the statement part of one
if
that has a single statement, then you should have braces on the statement of the contained statement:
if (FileOutOpen)
{
if (FileOut != null)
FileOut.Close();
}
Would be more consistent as:
if (FileOutOpen)
{
if (FileOut != null)
{
FileOut.Close();
}
}
Mixing styles is not a good idea!