Note that there are some explanatory texts on larger screens.

plurals
  1. POImplementing IEnumerable. Error.
    primarykey
    data
    text
    <p>my Code is :</p> <pre><code>using System; using System.Threading; using System.Collections; using System.Collections.Generic; namespace IEnumerable { public class MyEnumerable&lt;T&gt; : IEnumerable&lt;T&gt; { public MyEnumerable(T[] items) { this.items = items; } public IEnumerator&lt;T&gt; GetEnumerator() { return new NestedEnumerator(this); } IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } // The enumerator definition. class NestedEnumerator : IEnumerator&lt;T&gt; { public NestedEnumerator(MyEnumerable&lt;T&gt; coll) { Monitor.Enter(coll.items.SyncRoot); this.index = -1; this.coll = coll; } public T Current { get { return current; } } object IEnumerator.Current { get { return Current; } } public bool MoveNext() { if (++index &gt;= coll.items.Length) { return false; } else { current = coll.items[index]; return true; } } public void Reset() { current = default(T); index = 0; } public void Dispose() { try { current = default(T); index = coll.items.Length; } finally { Monitor.Exit(coll.items.SyncRoot); } } private MyEnumerable&lt;T&gt; coll; private T current; private int index; } private T[] items; } public class EntryPoint { static void Main() { MyEnumerable&lt;int&gt; integers = new MyEnumerable&lt;int&gt;(new int[] { 1, 2, 3, 4 }); foreach (int n in integers) { Console.WriteLine(n); } } } } </code></pre> <p>I am implementing this piece of code But i get an error. Can anybody help me what to do to error free this code? please help. My Errors are : </p> <p>1->'IEnumerable' is a 'namespace' but is used like a 'type' </p> <p>2->'IEnumerable.MyEnumerable' does not implement interface member 'System.Collections.IEnumerable.GetEnumerator()'. 'IEnumerable.MyEnumerable.GetEnumerator()' cannot implement 'System.Collections.IEnumerable.GetEnumerator()' because it does not have the matching return type of 'System.Collections.IEnumerator'. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload