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. How to implement IEnumerator with generics?

How to implement IEnumerator with generics?

Scheduled Pinned Locked Moved C#
helpquestiontutorial
2 Posts 1 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.
  • T Offline
    T Offline
    t800t8
    wrote on last edited by
    #1

    I implement my class like this using System.Collections; using System.Collections.Generic; namespace TryCollection.PositionEngine { class Tag : IEnumerable { #region Declare variables for internal use private List pointList = null; #endregion #region Declare variables for properties private string name; #endregion #region Constructors public Tag(string name) { this.name = name; pointList = new List(); } #endregion #region Properties public string Name { get { return name; } } #endregion #region Methods public void Add(Point point) { pointList.Add(point); } public IEnumerator GetEnumerator() { return pointList.GetEnumerator(); } #endregion } } but when I compile it, it shows me an error that 'TryCollection.PositionEngine.Tag' does not implement interface member 'System.Collections.IEnumerable.GetEnumerator()'. 'TryCollection.PositionEngine.Tag.GetEnumerator()' is either static, not public, or has the wrong return type. How can I implement System.Collections.IEnumerable.GetEnumerator() while I already have 'System.Collections.Generic.IEnumerable.GetEnumerator()? Help me! Thanks! I'm ... a fan of Manchester United a fan of Ozzy Osbourne a King of Nothing -- modified at 3:42 Thursday 26th January, 2006

    T 1 Reply Last reply
    0
    • T t800t8

      I implement my class like this using System.Collections; using System.Collections.Generic; namespace TryCollection.PositionEngine { class Tag : IEnumerable { #region Declare variables for internal use private List pointList = null; #endregion #region Declare variables for properties private string name; #endregion #region Constructors public Tag(string name) { this.name = name; pointList = new List(); } #endregion #region Properties public string Name { get { return name; } } #endregion #region Methods public void Add(Point point) { pointList.Add(point); } public IEnumerator GetEnumerator() { return pointList.GetEnumerator(); } #endregion } } but when I compile it, it shows me an error that 'TryCollection.PositionEngine.Tag' does not implement interface member 'System.Collections.IEnumerable.GetEnumerator()'. 'TryCollection.PositionEngine.Tag.GetEnumerator()' is either static, not public, or has the wrong return type. How can I implement System.Collections.IEnumerable.GetEnumerator() while I already have 'System.Collections.Generic.IEnumerable.GetEnumerator()? Help me! Thanks! I'm ... a fan of Manchester United a fan of Ozzy Osbourne a King of Nothing -- modified at 3:42 Thursday 26th January, 2006

      T Offline
      T Offline
      t800t8
      wrote on last edited by
      #2

      Oop, I fixed it myself. Thanks anyway! using System.Collections; using System.Collections.Generic; namespace TryCollection.PositionEngine { class Tag : IEnumerable { #region Declare variables for internal use private List pointList = null; #endregion #region Declare variables for properties private string name; #endregion #region Constructors public Tag(string name) { this.name = name; pointList = new List(); } #endregion #region Properties public string Name { get { return name; } } #endregion #region Methods public void Add(Point point) { pointList.Add(point); } public IEnumerator GetEnumerator() { return pointList.GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } #endregion } } I'm ... a fan of Manchester United a fan of Ozzy Osbourne a King of Nothing

      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