wossname
Dec 2nd, 2003, 03:48 AM
I get compiler error: Use of unassigned local variable 'MySW'
The line in the Finally block causes this. It is clearly being assigned to in the Try {} block. What gives?
//C#
void SeriousErrorMessage(string msg, string category)
{
StreamWriter MySW;
try
{
//write the error message to a local file on the HDD
MySW = new StreamWriter(itsLocalLogPath + "_" + category + "_" + DateTime.Now.ToShortDateString() + "_" + DateTime.Now.ToShortTimeString() + EXTN_LOG_FILE, false);
MySW.Write(msg);
}
finally
{
MySW.Close(); //close the new file
}
}
The line in the Finally block causes this. It is clearly being assigned to in the Try {} block. What gives?
//C#
void SeriousErrorMessage(string msg, string category)
{
StreamWriter MySW;
try
{
//write the error message to a local file on the HDD
MySW = new StreamWriter(itsLocalLogPath + "_" + category + "_" + DateTime.Now.ToShortDateString() + "_" + DateTime.Now.ToShortTimeString() + EXTN_LOG_FILE, false);
MySW.Write(msg);
}
finally
{
MySW.Close(); //close the new file
}
}