Hi,
I am using arraylist, in which I have added some number. I want to count total number of occurrences of number? Like,
ArrayList ar=new Arraylist();
ar.Add(2);ar.Add(3);ar.Add(3);ar.Add(2);ar.Add(2);ar.Add(7);ar.Add(2);ar.Add(2);
Output should be like this. 2 - 5 times
3 - 2 times
7 - 1 times
Is there any method which can solve this problem without writing full code or I have to take all numbers and check with all remaining numbers? Please help me.
Thanks in advance.
How to count total number of occurrence
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.

Mukesh KumarRank #615 · 3.9K reputationPosted Jan 12, 2012, 6:41 PM EST
Try this:
var l1 = new List
var g = l1.GroupBy(i => i);
foreach (var grp in g)
{
Console.WriteLine("{0} - {1} Times", grp.Key, grp.Count());
}
Alok PandeyRank #271 · 9.3K reputationPosted Jan 12, 2012, 7:15 PM EST