How to implement IEnumerator with generics?
-
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 -
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, 2006Oop, 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