title: Read lines batch wise in c#
body: <p>I have below code which is reading a .json stream line by line. since it will be a lengthy process, I have decided that I will take 100 lines at a time before I call my main function. and so the below code works fine. but this also gives me an issue if number of lines is less than 100, in that case my main function will not be called. how can I optimize my below code to handle both the scenario i.e. read maximum 100 lines at a time and pass it to main function or read all the lines if it is below 100</p>
  <pre class="lang-cs prettyprint-override"><code>public async void ReadJsonStream()
  {
      JsonSerializer serializer = new JsonSerializer();
  
      using (Stream data = await manager.DownloadBlob(null, &quot;TestMultipleLines.json&quot;, null))
      {
          using (StreamReader streamReader = new StreamReader(data, Encoding.UTF8))
          {
              int counter = 1;
              List&lt;string&gt; lines = new List&lt;string&gt;();
              
              while (streamReader.Peek() &gt;= 0)
              {
                  lines.Add(streamReader.ReadLine());
  
                  if (counter == 100)
                  {
                      counter = 1;
                      // call main function with line
                      lines.Clear();
                  }
                  counter++;
              }
          }
      }
  }
  </code></pre>