fork(1) download
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. public class Test
  5. {
  6. public static void Main()
  7. {
  8. int j = 0;
  9. foreach(var num in Example())
  10. {
  11. Console.WriteLine(num);
  12. j++;
  13. if(j == 3)
  14. break;
  15. }
  16. }
  17.  
  18. public static IEnumerable<int> Example()
  19. {
  20. try
  21. {
  22. for(int i = 0; i < 10; i++)
  23. {
  24.  
  25. Console.WriteLine("Before yield {0}", i);
  26. yield return i;
  27. Console.WriteLine("After yield {0}", i);
  28. }
  29. }
  30. finally
  31. {
  32. Console.WriteLine("In block finally");
  33. }
  34. }
  35. }
Success #stdin #stdout 0.03s 34752KB
stdin
Standard input is empty
stdout
Before yield 0
0
After yield 0
Before yield 1
1
After yield 1
Before yield 2
2
In block finally