Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Custom Stack

Custom Stack

Scheduled Pinned Locked Moved C#
data-structureshelpquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    Hyland Computer Systems
    wrote on last edited by
    #1

    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

    P 1 Reply Last reply
    0
    • H Hyland Computer Systems

      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

      P Offline
      P Offline
      PicklesTheClown
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups