Reply to comment

so we implement the enumerable interface with Link in such a way

Why would we need to?

Lets say i have a list of rectangle objects i need to enumerate through via foreach. so we implement the enumerable interface with Link in such a way using List<T>.

    public class RectangleStartingPoints<T> : IEnumerable<T>
    {

        List<T> _items = new List<T>();

        public void Add(T item)
        {
            _items.Add(item);
            
        }

        public IEnumerator<T> GetEnumerator()
        {
            foreach (T item in _items)
            {
                yield return item;
            }
        }

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return this.GetEnumerator();
        }

    }

since we've implemented using List<T> we can foreach all we want. or maybe i missed something?

Reply

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <b> <blockquote> <br> <code> <dd> <dl> <dt> <hr> <h1> <h2> <h3> <i> <img> <li> <ol> <p> <pre> <table> <td> <th> <tr> <tt> <u> <ul>
  • Images can be added to this post.

More information about formatting options