fork download
  1. using System;
  2.  
  3. public class Test
  4. {
  5. public static void Main()
  6. {
  7. var items = new int[] {1, 2, 3, 4, 5, 6, 7};
  8.  
  9. var enumerator = items.GetEnumerator();
  10.  
  11. using (enumerator as IDisposable)
  12. {
  13. var exists = enumerator.MoveNext();
  14.  
  15. if (exists)
  16. {
  17. do
  18. {
  19. var item = enumerator.Current;
  20. exists = enumerator.MoveNext();
  21.  
  22. Console.WriteLine(exists ? "{0}" : "{0} is the last one", item);
  23. }
  24. while (exists);
  25. }
  26. }
  27. }
  28. }
Success #stdin #stdout 0s 29664KB
stdin
Standard input is empty
stdout
1
2
3
4
5
6
7 is the last one