M
Mikep
Hi --
I'm sort of a newbi with C# and I have a question about scoping -- here's
what I'm trying to do:
StreamWriter swOutput;
if (condition)
{
//assemble a file name
string filename = "MyFile";
swOutput = new StreamWriter(filename)
}
else
{
swOutput.WriteLine("Data"); << using an unitialized variable
}
I can't create the file name until the condition is true and then I write to
the file. But there doesn't appear to be a good place to declare the
StreamWriter where it can be seen by both the true and false conditions. In
the above case, the compiler complains that I'm trying to use an
ininitialized variable.
TIA
Mike P
I'm sort of a newbi with C# and I have a question about scoping -- here's
what I'm trying to do:
StreamWriter swOutput;
if (condition)
{
//assemble a file name
string filename = "MyFile";
swOutput = new StreamWriter(filename)
}
else
{
swOutput.WriteLine("Data"); << using an unitialized variable
}
I can't create the file name until the condition is true and then I write to
the file. But there doesn't appear to be a good place to declare the
StreamWriter where it can be seen by both the true and false conditions. In
the above case, the compiler complains that I'm trying to use an
ininitialized variable.
TIA
Mike P