title: String Builder vs Lists
body: <p>I am reading in multiple files in with millions of lines and I am creating a list of all line numbers that have a specific issue. For example if a specific field is left blank or contains an invalid value.</p>
  
  <p>So my question is what would be the most efficient date type to keep track of a list of numbers that could be upwards of a million number of rows. Would using String Builder, Lists, or something else be more efficient?</p>
  
  <p>My end goal is to out put a message like "Specific field is blank on 1-32, 40, 45, 47, 49-51, etc. So in the case of a String Builder, I would check the previous value and if it is is only 1 more I would change it from 1 to 1-2 and if it was more than one would separate it by a comma. With the List, I would just add each number to the list and then combine then once the file has been completely read. However in this case I could have multiple list containing millions of numbers. </p>
  
  <p>Here is the current code I am using to combine a list of numbers using String Builder:</p>
  
  <pre><code>string currentLine = sbCurrentLineNumbers.ToString();
  string currentLineSub;
  
  StringBuilder subCurrentLine = new StringBuilder();
  StringBuilder subCurrentLineSub = new StringBuilder();
  
  int indexLastSpace = currentLine.LastIndexOf(' ');
  int indexLastDash = currentLine.LastIndexOf('-');
  
  int currentStringInt = 0;
  
  if (sbCurrentLineNumbers.Length == 0)
  {
      sbCurrentLineNumbers.Append(lineCount);
  }
  else if (indexLastSpace == -1 &amp;&amp; indexLastDash == -1)
  {
      currentStringInt = Convert.ToInt32(currentLine);
  
      if (currentStringInt == lineCount - 1)
          sbCurrentLineNumbers.Append("-" + lineCount);
      else
      {
          sbCurrentLineNumbers.Append(", " + lineCount);
          commaCounter++;
      }
  }
  else if (indexLastSpace &gt; indexLastDash)
  {
      currentLineSub = currentLine.Substring(indexLastSpace);
      currentStringInt = Convert.ToInt32(currentLineSub);
  
      if (currentStringInt == lineCount - 1)
          sbCurrentLineNumbers.Append("-" + lineCount);
      else
      {
          sbCurrentLineNumbers.Append(", " + lineCount);
          commaCounter++;
      }
  }
  else if (indexLastSpace &lt; indexLastDash)
  {
      currentLineSub = currentLine.Substring(indexLastDash + 1);
      currentStringInt = Convert.ToInt32(currentLineSub);
  
      string charOld = currentLineSub;
      string charNew = lineCount.ToString();
  
      if (currentStringInt == lineCount - 1)
          sbCurrentLineNumbers.Replace(charOld, charNew);
      else
      {
          sbCurrentLineNumbers.Append(", " + lineCount);
          commaCounter++;
      }
  }   
  </code></pre>