In my c# program, I'm reading in lines from a text file and want to check to see if the line that I read in contains the string "EHRS" and if it does, I want to put that line into an array and if not, I want to read in the next line. When I run this, I get an error that tells me that an unhandled exception of type 'System.NullReferenceException' occurred at the line where I use the contains function.
Here's what I have:
string[] concArray = new string[numLinesConcYr];
using (var sr = new StreamReader(mydocpath + @"\concYrLines.txt"))
{
for (int i = 0; i < numLinesConcYr; i++)
{
concYrLine = sr.ReadLine();
if (concYrLine.Contains("EHRS") == true)
{
concArray[i] = concYrLine;
}
else
{
concYrLine = sr.ReadLine();
}
}
}