Custom Stack
-
I get this error when I try to use implement the IEnumerable interface: Error 1 'generics.GenStack' does not implement interface member 'System.Collections.IEnumerable.GetEnumerator()'. 'generics.GenStack.GetEnumerator()' is either static, not public, or has the wrong return type. Here is the code segment: // Custom Stack - designed to accept class instances only public class GenStack: IEnumerable where T : class { private T[] stackCollection; private int count = 0; // Constructor public GenStack(int size) { stackCollection = new T[size]; } public IEnumerator GetEnumerator() { string totList = ""; for (int i = 0; i < count; i++) { yield return stackCollection[i]; totList+= stackCollection[i]+" "; } object ob = totList ; yield return (T)ob; } . . } I am implementing the GetEnumerator(), though. Am I missing something? Thanks in advance
-
I get this error when I try to use implement the IEnumerable interface: Error 1 'generics.GenStack' does not implement interface member 'System.Collections.IEnumerable.GetEnumerator()'. 'generics.GenStack.GetEnumerator()' is either static, not public, or has the wrong return type. Here is the code segment: // Custom Stack - designed to accept class instances only public class GenStack: IEnumerable where T : class { private T[] stackCollection; private int count = 0; // Constructor public GenStack(int size) { stackCollection = new T[size]; } public IEnumerator GetEnumerator() { string totList = ""; for (int i = 0; i < count; i++) { yield return stackCollection[i]; totList+= stackCollection[i]+" "; } object ob = totList ; yield return (T)ob; } . . } I am implementing the GetEnumerator(), though. Am I missing something? Thanks in advance
A little curious by your code snippet. Try:
public class GenStack : IEnumerable where T:class { public GenStack(...) { ... } public IEnumerator GetEnumerator() { } System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { } }
-- modified at 16:53 Tuesday 14th February, 2006