The compiler is reading Error: Use of unassigned local variable 'fileData'.
I have searched but none of the things I have tried solved my problem.
private ScrPrnData ParseTemperatureFileLine(string sLine)
{
char[] delimiter = { '\t' };
string[] elements = sLine.Split(delimiter, 200);
ScrPrnData fileData;
fileData.dTempZone1 = double.Parse(elements[0].Trim());
开发者_运维百科 fileData.dTempZone2 = double.Parse(elements[1].Trim());
fileData.dTempZone3 = double.Parse(elements[2].Trim());
fileData.dTempZone4 = double.Parse(elements[3].Trim());
return fileData;
}
private ScrPrnData ParseTemperatureFileLine(string sLine)
{
...
ScrPrnData fileData = new ScrPrnData();
...
}
You have to create an actual object of that type:
ScrPrnData fileData = new ScrPrnData();
You're never initializing fileData
and compiler is saving you the obvious NullReferenceException at runtime.
ScrPrnData fileData; // <- need to initialize this here.
// fileData will always be null here and throw an Exception
// the compiler knows this and is saving you the headache
fileData.dTempZone1 = double.Parse(elements[0].Trim());
You're using fileData without initializing it with some value. Try:
ScrPrnData fileData = new ScrPrnData();
or something to that effect.
You need to instantiate it.
ScrPrnData fileData; = new ScrPrnData ();
精彩评论