title: Read a Text File and Populate an Array
body: <p>I am to read a file and populate a String array. My data is like:</p>
  
  <blockquote>
    <p>Accident.<br>
    An unplanned event, unexpected and undesigned, which occurs suddenly and at a definite place.</p>
    
    <p>Accident Frequency.<br>
    The rate of the occurrence of accidents, often expressed in terms of the number of accidents over a period of time. It is one method used for measuring the effectiveness of loss prevention services. Contrast with Accident Severity.  </p>
    
    <p>Accident Prevention.<br>
    See Loss Prevention Service.  </p>
    
    <p>Accident Severity.<br>
    A measure of the severity or seriousness of losses, rather than the number of losses. It is measured in terms of time lost from work rather than the number of individual accidents. It is another way of measuring the effectiveness of loss prevention services. Contrast with Accident Frequency.  </p>
  </blockquote>
  
  <p>My code is:</p>
  
  <pre><code>private void openfile_Click(object sender, EventArgs e)
  {
      if (text.Text == String.Empty)
      {
          err.SetError(text, "Needs to contain Text");
      }
  
      DialogResult result = open_dialog.ShowDialog();
  
      if (result == DialogResult.OK)
      {
          try
          {
              string file_name = open_dialog.FileName;
              System.IO.StreamReader sr = new System.IO.StreamReader(file_name);
  
              String line;
              String[] wordslist=new String[count];
  
              using (StreamReader reader = File.OpenText(file_name))
              {
                  // read each line, ensuring not null (EOF)
                  while ((line = reader.ReadLine()) != null)
                  {
                      if (line == String.Empty)
                      {
                      }
                      else
                      {
                          wordslist = line.Split(' ');
                          count += 1;
                      }
                  }
              }
  
              for (int i=0;i&lt;wordslist.Length;i++)
              {
                  //if (str==(text.Text))
                  //{
                      //var index = Array.FindIndex(wordslist, row =&gt; row.Contains(text.Text));
                      Console.WriteLine("\ncapacity " + wordslist[i]);
                      //Console.WriteLine("\n" + wordslist[index - 1]+" capacity");
                 //}
  
              }
          }
          catch (Exception ex)
          {
              Console.WriteLine("\n\nERROR= " + ex);
          }
      }
  }
  </code></pre>
  
  <p>I simply want to print the contents of the array being populated with the file contents but the array is not being populated. But when I remove the Blank lines between my data the array will be populated with some few lines and I'm able to print some but not ALL contents.</p>
  
  <p>The problem is that my data is so large that I can't remove lines and don't want to be! Is there any solution so that i can do this thing correctly? </p>