title: Reading a text file and processing it line by line
body: <p>I have a text file i want my program to :</p>
  
  <p>1 - display number of lines and file path .</p>
  
  <p>2 - loop through each line .</p>
  
  <pre><code>var lines = File.ReadLines(@"C:\\test.txt");                
  </code></pre>
  
  <p><strong>Edited (The Answer)</strong></p>
  
  <pre><code>public static string[] local_file; // make a string array to load the file into it
  int i = 0; // index of lines 
    try 
      {
          OpenFileDialog op = new OpenFileDialog // use OpenFileDialog to choose your file
          {
              Filter = "Combos file (*.txt)|*.txt" ;// select only text files
          }
          if (op.ShowDialog() == DialogResult.OK)
          {
  
              local_file= File.ReadAllLines(op.FileName);// load all the contents of the file into the array 
  
              string count = "lines = " + Convert.ToString(local_file.Length); // number of lines 
  
              string file_name = op.FileName; // show the file name including the path
          }
          for (i; i &lt; local_file.Length; i++)// loop through each line 
              {
               // do something here remember to use local_file[i] for the lines
              }
  
      }catch (Exception exception)
      {
          MessageBox.Show(exception.Message);
      }
  </code></pre>