Count all duplicates items and determine average time of each duplicate ocurrance of array of strings
<p>I have an array that contains data as follows (string and time data separated by a comma):</p>

<p>array[0]= Channel 1, 01:05:36</p>

<p>array[1]= Channel 2, 02:25:36</p>

<p>array[2]= Group 1, 22:25:36</p>

<p>array[3]= Netwk, 41:40:09</p>

<p>array[4]= LossOf, 03:21:17</p>

<p>array[5]= LossOf, 01:13:28</p>

<p>array[6]= Channel 1, 04:25:36</p>

<p>array[7]= Channel 2, 00:25:36</p>

<p>.
.
.
array[xxx]= xxx, xxx</p>

<p>I would like to count all duplicates items and determine average time for each duplicate found as follows:</p>

<p>Item1,  Channel 1, 2 occurrences, average time for each occurrence is about xx minutes</p>

<p>Item2,  Channel 2, 2 occurrences, average time for each occurrence is about xx minutes</p>

<p>Item3,  LossOf, 2 occurrences, average time for each occurrence is about xx minutes</p>

<p>The time format is hh:mm:ss</p>

<p>This is what I have done so far, which only gives me total times of duplicates:</p>

<pre><code>public void CountDuplicates(string[] myStringArray)
{
  //count duplicates
  ArrayList list = new ArrayList();
  int  loopCnt=0;

  foreach (string item in myStringArray)
  {
    if (!String.IsNullOrEmpty(myStringArray[loopCnt]) == true)
      list.Add(item);
    loopCnt++;
  }

  loopCnt = 0;
  Dictionary&lt;string, int&gt; distinctItems = new Dictionary&lt;string, int&gt;();
  foreach (string item in list)
  {
    if (!distinctItems.ContainsKey(item))
    {
      distinctItems.Add(item, 0);
      loopCnt++;
    }
    distinctItems[item] += 1;
  }
  foreach (KeyValuePair&lt;string, int&gt; distinctItem in distinctItems)
  {
    txtDisplayResults.AppendText("Alarm Error: " + distinctItem.Key + ",  How many times: " + distinctItem.Value + "\r\n");
  }
}
</code></pre>
