title: An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
body: <p>In the following code, I got following error.</p>
  <blockquote>
  <p>An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll</p>
  <p>Additional information: Index was out of range. Must be non-negative and less than the size of the collection.</p>
  </blockquote>
  <p>Here is code:</p>
  <pre><code>public ProcessInformation GetMaxRunTimeForApplicationsBetween(DateTime StartingTime, DateTime EndingTime)
      {
  
          //Filter Based on Timer
          List&lt;ProcessInformation&gt; filterList = new List&lt;ProcessInformation&gt;();
  
          foreach (HarvestApp.ProcessInformation item in this.ProcessList)
          {
              if (item.started_at.CompareTo(StartingTime) &gt;= 0 &amp;&amp; item.ended_at.CompareTo(EndingTime) &lt;= 0)
              {
                  filterList.Add(item);
              }
          }
  
          //Count Max Occurrence of Application
          List&lt;int&gt; countApplicationList = new List&lt;int&gt;();
          List&lt;string&gt; applicationNameList = new List&lt;string&gt;();
          
  
          foreach (HarvestApp.ProcessInformation item in filterList)
          {
              if (applicationNameList.Contains(item.name))
              {
                  countApplicationList[applicationNameList.IndexOf(item.name)]++;
              }
              else
              {
                  applicationNameList.Add(item.name);
                  countApplicationList.Add(1);
                  
              }
          }
  
  
          //if (countApplicationList.Count == 0)
          //{
          //    throw new InvalidOperationException(&quot;Empty list&quot;);
          //}
  
  
          int max = int.MinValue;
          foreach (int item in countApplicationList)
          {
              if (item &gt; max)
              {
                  max = item;
              }
           
          }
          
              //Return corresponding ProcessInformation Class of applicationNameList
              return filterList[filterList.FindIndex(delegate
                  (ProcessInformation proc)
                  {
                      return proc.name.Equals(applicationNameList[countApplicationList.IndexOf(max)], StringComparison.Ordinal);
                  })];
  
         
  
  
      }
  </code></pre>