fork(1) 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. var mainList = new List<string>
  10. {"Reset", "Set", "Test", "Test", "Reset", "Test", "Test"};
  11. var i = 1;
  12. var result = mainList
  13. .Select(str =>
  14. {
  15. if (str == "Reset") i++;
  16. return new {str, i};
  17. })
  18. // ^^ Above I make partitions by `i`; that `i` will change by watching a `Reset`
  19. .GroupBy(g => g.i)
  20. .Select(g => g.Select(c => c.str).ToList());
  21. // then I just group by `i` as partition then removing it from results.
  22.  
  23. foreach (var item in result)
  24. {
  25. foreach (var str in item)
  26. {
  27. Console.Write($"{str}, ");
  28. }
  29. Console.WriteLine();
  30. }
  31. }
  32. }
Success #stdin #stdout 0.01s 131776KB
stdin
Standard input is empty
stdout
Reset, Set, Test, Test, 
Reset, Test, Test,