fork(37) download
  1. using System;
  2. using System.Globalization;
  3. using System.Linq;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6.  
  7. public class Test
  8. {
  9. class grpitem
  10. {
  11. public string groupCode;
  12. public string item;
  13. }
  14.  
  15. static List<grpitem> list = new List<grpitem>()
  16. {
  17. new grpitem() {groupCode="3", item="b"},
  18. new grpitem() {groupCode="1", item="b"},
  19. new grpitem() {groupCode="3", item="c"},
  20. new grpitem() {groupCode="2", item="b"},
  21. new grpitem() {groupCode="2", item="a"},
  22. new grpitem() {groupCode="2", item="c"},
  23. new grpitem() {groupCode="1", item="a"},
  24. new grpitem() {groupCode="3", item="a"},
  25. new grpitem() {groupCode="3", item="d"}
  26. };
  27. public static void Main()
  28. {
  29. IEnumerable<grpitem> ordered = list.GroupBy(grp => grp.groupCode)
  30. .SelectMany(g => g.OrderBy(grp => grp.item));
  31.  
  32. foreach(grpitem g in ordered)
  33. Console.WriteLine("groupCode:{0} item:{1}",g.groupCode,g.item);
  34.  
  35. }
  36. }
  37.  
Success #stdin #stdout 0.08s 34144KB
stdin
Standard input is empty
stdout
groupCode:3 item:a
groupCode:3 item:b
groupCode:3 item:c
groupCode:3 item:d
groupCode:1 item:a
groupCode:1 item:b
groupCode:2 item:a
groupCode:2 item:b
groupCode:2 item:c