static void Main() { MyColl <int> integers = new MyColl <int>(new int[] { 1, 2, 3, 4 }); foreach (int n in integers) { Console.WriteLine(n); } }
static void Main() { var myColl = new MyColl <int>(new[] { 1, 2, 3, 4 }); foreach (int i in myColl) { Console.WriteLine(i); } var collExtension = new MyCollExtension <int>(myColl); IEnumerator <int> enumerator = collExtension.GetEnumerator(false); while (enumerator.MoveNext()) { Console.WriteLine(enumerator.Current); } Console.ReadKey(); }
static void Main() { MyColl <int> integers = new MyColl <int>(new int[] { 1, 2, 3, 4 }); IEnumerator <int> enumerator = integers.GetEnumerator(new ImmutableBool(true)); // Get reference to synchronized field. object field = enumerator.GetType(). GetField("synchronized").GetValue(enumerator); while (enumerator.MoveNext()) { Console.WriteLine(enumerator.Current); // Throws an exception. field.GetType().GetProperty("Value"). SetValue(field, false, null); } }
// entry point static void Main(string[] args) { MyColl coll = new MyColl(); var lst = coll.GetList(); // print only numbers which are less than 200 fromthe list // print only prime number from the list for (int i = 0; i <= 250; i++) { if (lst[i] < 200) { Console.WriteLine($"value at index {i} == {lst[i]}"); } } //Console.WriteLine(lst[4]); }
public MyCollExtension(MyColl <T> myColl) { _myColl = myColl; }
public MyCollExtension(T[] items) : base(items) { _myColl = new MyColl <T>(items); }
public NestedEnumerator(MyColl <T> coll) { Monitor.Enter(coll.items.SyncRoot); this.index = -1; this.coll = coll; }