fork(1) download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.IO;
  6.  
  7. namespace Program {
  8. class Stahl {
  9. public int Laenge { get; set; }
  10. public int Nr { get; set; }
  11. };
  12.  
  13. class StahlComparer : IComparer<Stahl> {
  14.  
  15. public int Compare(Stahl x, Stahl y) {
  16. if (x.Nr > y.Nr) return 1;
  17. else if (x.Nr < y.Nr) return -1;
  18. return 0;
  19. }
  20. };
  21.  
  22. class Program {
  23. static void Main(string[] args) {
  24. var stalhs = new List<Stahl>() {
  25. new Stahl{ Laenge = 36, Nr = 8 },
  26. new Stahl{ Laenge = 36, Nr = 12 },
  27. new Stahl{ Laenge = 36, Nr = 14 },
  28. new Stahl{ Laenge = 30, Nr = 12 },
  29. new Stahl{ Laenge = 30, Nr = 4 },
  30. new Stahl{ Laenge = 36, Nr = 12 },
  31. new Stahl{ Laenge = 30, Nr = 12 },
  32. new Stahl{ Laenge = 30, Nr = 12 }
  33. };
  34.  
  35. stalhs.Sort(new StahlComparer());
  36. Console.WriteLine("Sorted List: ");
  37. foreach (var stahl in stalhs) Console.WriteLine("{0}, {1}", stahl.Laenge, stahl.Nr);
  38.  
  39. var counts = stalhs.GroupBy(obj => new { obj.Laenge, obj.Nr }).ToDictionary(obj => obj.Key, obj => obj.Count());
  40.  
  41. Console.WriteLine("\nOccurences: ");
  42. foreach (var count in counts) Console.WriteLine("{0}, {1}", count.Key, count.Value);
  43. }
  44. }
  45. }
Success #stdin #stdout 0.06s 24280KB
stdin
Standard input is empty
stdout
Sorted List: 
30, 4
36, 8
30, 12
36, 12
30, 12
36, 12
30, 12
36, 14

Occurences: 
{ Laenge = 30, Nr = 4 }, 1
{ Laenge = 36, Nr = 8 }, 1
{ Laenge = 30, Nr = 12 }, 3
{ Laenge = 36, Nr = 12 }, 2
{ Laenge = 36, Nr = 14 }, 1