Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. class Parent
  2. {
  3. public int MyProperty { get; set; }
  4. public void GetData()
  5. {
  6. Console.WriteLine("parent");
  7. }
  8. }
  9.  
  10.  
  11.  
  12. Parent[] p = new Parent[3]
  13. {
  14. new Parent(){MyProperty=90},
  15. new Parent(){MyProperty=50},
  16. new Parent(){MyProperty=100}
  17. };
  18.  
  19.  
  20. foreach (var item in p)
  21. {
  22. Parent it = item;
  23. Console.WriteLine(it.MyProperty);
  24. }
  25.  
  26. public abstract class Array : ICloneable, IList, ICollection,
  27. IEnumerable, IStructuralComparable, IStructuralEquatable
  28.  
  29. public interface ICollection<T> : IEnumerable<T>, IEnumerable
  30.  
  31. public class Foo<T>
  32. {
  33. public Foo(T value)
  34. {
  35. Value = value;
  36. }
  37.  
  38. public T Value { get; }
  39.  
  40. public FooEnumerator<T> GetEnumerator()
  41. {
  42. return new FooEnumerator<T>(Value);
  43. }
  44. }
  45.  
  46. public class FooEnumerator<T>
  47. {
  48. private bool _hasValue = true;
  49. private readonly T _value;
  50.  
  51. public FooEnumerator(T value)
  52. {
  53. _value = value;
  54. }
  55.  
  56. public bool MoveNext()
  57. {
  58. if (_hasValue)
  59. {
  60. Current = _value;
  61. return true;
  62. }
  63. else
  64. {
  65. _hasValue = false;
  66. return _hasValue;
  67. }
  68. }
  69.  
  70. public T Current { get; private set; }
  71. }
  72.  
  73. public class Test
  74. {
  75. public static void Run()
  76. {
  77. foreach (var x in new Foo<int>(1))
  78. {
  79. Console.WriteLine(x);
  80. }
  81. }
  82. }
  83.  
  84. public class Foo<T>
  85. {
  86. public Foo(T value)
  87. {
  88. Value = value;
  89. }
  90.  
  91. public T Value { get; }
  92.  
  93. public Foo<U> Select<U>(Func<T, U> f)
  94. {
  95. return new Foo<U>(f(Value));
  96. }
  97.  
  98. public Foo<U> SelectMany<U>(Func<T, Foo<U>> f)
  99. {
  100. return f(Value);
  101. }
  102.  
  103. public Foo<V> SelectMany<U, V>(Func<T, Foo<U>> f, Func<T, U, V> g)
  104. {
  105. return new Foo<V>(g(Value, f(Value).Value));
  106. }
  107. }
  108.  
  109. public class Test
  110. {
  111. public static void Run()
  112. {
  113. var result =
  114. from x in new Foo<int>(5)
  115. from y in new Foo<int>(9)
  116. select (x + y).ToString();
  117.  
  118. // result is now a Foo<string> containing the value "14"
  119. }
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement