fork download
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. public class Test
  6. {
  7. static IEnumerable<T> Join<T>(T separator, IEnumerable<T> items) {
  8. bool first = true;
  9. foreach (var item in items) {
  10. if (!first) {
  11. yield return separator;
  12. } else {
  13. first = false;
  14. }
  15. yield return item;
  16. }
  17. }
  18. public static void Main()
  19. {
  20. List<int> list = new List<int> {1, 2, 3, 4, 5};
  21. foreach (var x in Join(-1, list)) {
  22. Console.WriteLine(x);
  23. }
  24. }
  25. }
Success #stdin #stdout 0s 29664KB
stdin
Standard input is empty
stdout
1
-1
2
-1
3
-1
4
-1
5