fork(10) download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. public class Test
  6. {
  7. public static void Main()
  8. {
  9. List<Prop> list = new List<Prop>();
  10. list.Add(new Prop("voltage", 7));
  11. list.Add(new Prop("voltage", 24));
  12. list.Add(new Prop("systemconfiguration", 2451));
  13. list.Add(new Prop("systemunit", 0));
  14. list.Add(new Prop("systemunit", 15));
  15. list.Add(new Prop("voltage", 0));
  16. var highestByTitle = list
  17. .GroupBy(t => t.title)
  18. .Select(g => g.OrderByDescending(t => t.val).First())
  19. .ToList();
  20. foreach (var p in highestByTitle) {
  21. Console.WriteLine("{0} - {1}", p.title, p.val);
  22. }
  23.  
  24.  
  25. }
  26.  
  27.  
  28. public class Prop {
  29. public Prop(string t, int v) {title = t; val = v;}
  30. public string title {get;set;}
  31. public int val {get;set;}
  32. }
  33.  
  34. }
Success #stdin #stdout 0.04s 16040KB
stdin
Standard input is empty
stdout
voltage - 24
systemconfiguration - 2451
systemunit - 15