fork(6) download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. public class Test
  7. {
  8. public static void Main()
  9. {
  10. var array = new int[] {1,1,1,2,2,2,2,3,3,9,9,16,16};
  11.  
  12. var query = from x in array
  13. group x by x into g
  14. let count = g.Count()
  15. select new {Value = g.Key, Count = count};
  16.  
  17. foreach (var x in query)
  18. {
  19. Console.WriteLine("Value: " + x.Value + " Count: " + x.Count);
  20. }
  21. }
  22. }
Success #stdin #stdout 0.05s 34152KB
stdin
Standard input is empty
stdout
Value: 1 Count: 3
Value: 2 Count: 4
Value: 3 Count: 2
Value: 9 Count: 2
Value: 16 Count: 2