This code(C# 2.0) doesn't compile. But why?
using System; using System.Collections.Generic; using System.Text; namespace Z int count; publicvoid Push(T data) { T[count] = data; count++; } public T Pop() { } public IEnumerator<T> GetEnumerator() for (int i = count - 1; i >= 0; --i) yieldreturn items[i ]; } class Program staticvoid Main() St<int> s =new St<int>(); for (int i = 0; i < 10; i++) s.Push(i); foreach (int iin s) Console.Write("{0}", i); } |
I am working with C# Express Beta 2. Try to compile and get an error:
Error 1 'Z.St<T>' does not implement interface member 'System.Collections.IEnumerable.GetEnumerator()'. 'Z.St<T>.GetEnumerator()' is either static, not public, or has the wrong return type. C:\Documents and Settings\LocalService\Local Settings\Application Data\Temporary Projects\ConsoleApplication1\Program.cs 7 18 IteratorsExample
But Z.St<T>.GetEnumerator() NOT static, IS public and has return type IEnumerator<T> ! Where I did wrong?

