fork(2) download
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6.  
  7.  
  8. internal class Program
  9. {
  10. private static void Main(string[] args)
  11. {
  12. var n = new InfiniteCollection<string>("asdf");
  13. foreach (var value in n.Take(5))
  14. {
  15. Console.WriteLine(value);
  16. }
  17. }
  18. }
  19.  
  20. class InfiniteCollection<T> : IEnumerable<T>
  21. {
  22. private T _value;
  23.  
  24. public InfiniteCollection(T value)
  25. {
  26. _value = value;
  27. }
  28.  
  29. public IEnumerator<T> GetEnumerator()
  30. {
  31. return new InfiniteEnumerator<T>(_value);
  32. }
  33.  
  34. IEnumerator IEnumerable.GetEnumerator()
  35. {
  36. return GetEnumerator();
  37. }
  38.  
  39. private class InfiniteEnumerator<T>:IEnumerator<T>
  40. {
  41. public InfiniteEnumerator(T value)
  42. {
  43. Current = value;
  44. }
  45. public void Dispose()
  46. {
  47. return;
  48. }
  49.  
  50. public bool MoveNext()
  51. {
  52. return true;
  53. }
  54.  
  55. public void Reset()
  56. {
  57. return;
  58. }
  59.  
  60. public T Current { get; }
  61.  
  62. object IEnumerator.Current
  63. {
  64. get { return Current; }
  65. }
  66. }
  67. }
Success #stdin #stdout 0.04s 24040KB
stdin
Standard input is empty
stdout
asdf
asdf
asdf
asdf
asdf