Do I need to implement IEnumerable on a collectionbase

Posted on 2005-03-17
Medium Priority
Last Modified: 2012-06-27

I have a custom class that derives from the collectionbase abstract class.

Every single thing I have read tells me that to allow foreach looping through the collection, I need to implement the IEnumerable interface.

The issue is that I have NOT implemented it, and I can foreach loop through my collection all day long??? Am I missing something here?

Below is the current code for this class (just starting)

public class ImageGallery:System.Collections.CollectionBase{
            //constructor method
            public ImageGallery(){
            //Add method to add GalleryImage to the collection
            public void Add(GalleryImage in_GalleryImage) {
            //add an indexer so the collection can use array style
            public GalleryImage this[int index] {
                  get { return (GalleryImage)this.InnerList[index]; }
                  set { this.InnerList[index] = value;}

Thanks !

Question by:WillyCornbread
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 10

Assisted Solution

smegghead earned 200 total points
ID: 13570687
you are inheriting from CollectionBase, which DOES implement IEnumerable.
LVL 18

Accepted Solution

testn earned 800 total points
ID: 13571930
as smegghead said, you don't need to implement that since CollectionBase is a complete class which implements everything you need for a collection already. However, you might want to implement your own IEnumerable, IEnumerator just to make it strongly typed.

check the sample from here

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question