fork(1) download
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4.  
  5. public class Test
  6. {
  7. public static void Main(string[] args)
  8. {
  9. foreach (var i in new DangerousEnumerable())
  10. {
  11. Console.WriteLine(i);
  12. }
  13. Console.ReadKey();
  14. }
  15. }
  16.  
  17. public class DangerousEnumerable : IEnumerable<int>, IDisposable
  18. {
  19. public IEnumerator<int> GetEnumerator()
  20. {
  21. yield return 1;
  22. yield return 2;
  23. Console.WriteLine("Finished!");
  24. }
  25.  
  26. IEnumerator IEnumerable.GetEnumerator()
  27. {
  28. return GetEnumerator();
  29. }
  30.  
  31. public void Dispose()
  32. {
  33. Console.WriteLine("Disposed!");
  34. }
  35. }
Success #stdin #stdout 0.03s 33960KB
stdin
Standard input is empty
stdout
1
2
Finished!