Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Parent
- {
- public int MyProperty { get; set; }
- public void GetData()
- {
- Console.WriteLine("parent");
- }
- }
- Parent[] p = new Parent[3]
- {
- new Parent(){MyProperty=90},
- new Parent(){MyProperty=50},
- new Parent(){MyProperty=100}
- };
- foreach (var item in p)
- {
- Parent it = item;
- Console.WriteLine(it.MyProperty);
- }
- public abstract class Array : ICloneable, IList, ICollection,
- IEnumerable, IStructuralComparable, IStructuralEquatable
- public interface ICollection<T> : IEnumerable<T>, IEnumerable
- public class Foo<T>
- {
- public Foo(T value)
- {
- Value = value;
- }
- public T Value { get; }
- public FooEnumerator<T> GetEnumerator()
- {
- return new FooEnumerator<T>(Value);
- }
- }
- public class FooEnumerator<T>
- {
- private bool _hasValue = true;
- private readonly T _value;
- public FooEnumerator(T value)
- {
- _value = value;
- }
- public bool MoveNext()
- {
- if (_hasValue)
- {
- Current = _value;
- return true;
- }
- else
- {
- _hasValue = false;
- return _hasValue;
- }
- }
- public T Current { get; private set; }
- }
- public class Test
- {
- public static void Run()
- {
- foreach (var x in new Foo<int>(1))
- {
- Console.WriteLine(x);
- }
- }
- }
- public class Foo<T>
- {
- public Foo(T value)
- {
- Value = value;
- }
- public T Value { get; }
- public Foo<U> Select<U>(Func<T, U> f)
- {
- return new Foo<U>(f(Value));
- }
- public Foo<U> SelectMany<U>(Func<T, Foo<U>> f)
- {
- return f(Value);
- }
- public Foo<V> SelectMany<U, V>(Func<T, Foo<U>> f, Func<T, U, V> g)
- {
- return new Foo<V>(g(Value, f(Value).Value));
- }
- }
- public class Test
- {
- public static void Run()
- {
- var result =
- from x in new Foo<int>(5)
- from y in new Foo<int>(9)
- select (x + y).ToString();
- // result is now a Foo<string> containing the value "14"
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement