Guest User

Untitled

a guest
Jul 19th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. option 1
  2. line a
  3. line b
  4. line c
  5. option 3
  6. line x
  7. line z
  8. line y
  9. option 2
  10. a1
  11. a4
  12. a2
  13. a3
  14.  
  15. option 1
  16. line a
  17. line b
  18. line c
  19. option 2
  20. a1
  21. a2
  22. a3
  23. a4
  24. option 3
  25. line x
  26. line y
  27. line z
  28.  
  29. static IEnumerable<string> Sort(IEnumerable<string> unsorted)
  30. {
  31. string option = null;
  32. return
  33. from line in unsorted
  34. let isSubitem = line.StartsWith(" ")
  35. let parent = isSubitem ? option : option = line
  36. orderby parent, isSubitem, line
  37. select line;
  38. }
  39.  
  40. static IEnumerable<string> Sort(IEnumerable<string> unsorted)
  41. {
  42. string option = null;
  43. return
  44. unsorted
  45. .OrderBy(line => line.StartsWith(" ") ? option : option = line)
  46. .ThenBy(line => line.StartsWith(" ") ? line : null);
  47. }
  48.  
  49. yourEnumerable.OrderBy(y => y.Key).ThenBy(y => y.Prop2)
  50.  
  51. string lineRead;
  52. string current;
  53. var dictionary = new Dictionary<string, List<string>>);
  54. while((lineRead = reader.ReadLine())
  55. {
  56. if(!lineRead.StartsWith(" "))
  57. {
  58. dictionary.Add(lineRead, new List<string>());
  59. current = lineRead;
  60. }
  61. else
  62. {
  63. dictionary[current].Add(lineRead);
  64. }
  65. }
  66.  
  67. dictionary.Keys.ToList().ForEach(y => dictionary[y] = dictionary[y].OrderBy(x => x).ToList());
  68. dictionary.OrderBy(y => y.Key);
  69.  
  70. .OrderBy(x => x.option)
  71. .ThenBy(x=>x.secondary)
  72.  
  73. list.OrderBy(<a delegate that will sort your array>).ThenBy(<a delegate that will sort your array again>)
Add Comment
Please, Sign In to add comment