How to check to see if my variable contains a string : <p>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.</p>

<p>Here's what I have:</p>

<pre><code>string[] concArray = new string[numLinesConcYr];

using (var sr = new StreamReader(mydocpath + @"\concYrLines.txt"))
{
    for (int i = 0; i &lt; numLinesConcYr; i++)
    {
        concYrLine = sr.ReadLine();
        if (concYrLine.Contains("EHRS") == true)
        {
            concArray[i] = concYrLine;
        }
        else
        {
            concYrLine = sr.ReadLine();
        }
    }
}
</code></pre>
