fork(2) download
  1. using System;
  2. using System.Linq;
  3.  
  4. public class Test
  5. {
  6. public static void Main()
  7. {
  8. int[] array = new int[10];
  9. array[0] = 1;
  10. array[1] = 1;
  11. array[2] = 1;
  12. array[3] = 2;
  13. array[4] = 1;
  14. array[5] = 2;
  15. array[6] = 1;
  16. array[7] = 1;
  17. array[8] = 2;
  18. array[9] = 3;
  19.  
  20. var countGroups = array.GroupBy(a => a)
  21. .OrderByDescending(g => g.Count());
  22.  
  23. foreach(var g in countGroups)
  24. Console.WriteLine("{0} => {1} times", g.Key, g.Count());
  25.  
  26.  
  27. }
  28. }
Success #stdin #stdout 0.05s 37240KB
stdin
Standard input is empty
stdout
1 => 6 times
2 => 3 times
3 => 1 times