We help IT Professionals succeed at work.
Get Started

Trying to create a collection class for my custom class and it's failing - Help!

Siv asked
Last Modified: 2015-08-17
I have a Class called DataExtractTable which matches a database table and I want to have another class that I can use to hold a collection of DataExtractTable records.  In my days as a VB programmer I had a template for creating my own Collection objects so that it implemented all the add remove iterate type functionality over a collection of my custom class objects. However now I am moving to use C# I decided that I ought to be able to use Generics and simplify things. This is what I have come up with as my collection class:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DataCollector
    public class DataExtractTablesColl : IEnumerable<DataExtractTable>
        public List<DataExtractTable> dets = new List<DataExtractTable>();

        public IEnumerator<DataExtractTable> GetEnumerator()
            return this.dets.GetEnumerator();

        public void Add(DataExtractTable d) 


Open in new window

Trouble is I am getting this error:
Error      1      'DataCollector.DataExtractTablesColl' does not implement interface member 'System.Collections.IEnumerable.GetEnumerator()'. 'DataCollector.DataExtractTablesColl.GetEnumerator()' cannot implement 'System.Collections.IEnumerable.GetEnumerator()' because it does not have the matching return type of 'System.Collections.IEnumerator'.      

I cannot see why it doesn't like my GetEnumerator, any help gratefully accepted.  If you think I am going about this the wrong way then please identify what I should be doing.

Watch Question
Top Expert 2015
This problem has been solved!
Unlock 1 Answer and 4 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE