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.
Loading
Mukesh KumarPosted Jan 12, 2012, 11:41 PM
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 PandeyPosted Jan 13, 2012, 12:15 AM