Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Do I need to implement IEnumerable on a collectionbase

Posted on 2005-03-17
2
Medium Priority
?
386 Views
Last Modified: 2012-06-27
hi,

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) {
                  List.Add(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 !

b
0
Comment
Question by:WillyCornbread
2 Comments
 
LVL 10

Assisted Solution

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

Accepted Solution

by:
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
http://www.csharphelp.com/archives/archive89.html
http://www.c-sharpcorner.com/Code/2002/Aug/StrongTypedCollections.asp
http://support.microsoft.com/kb/307484/EN-US/
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

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 aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

571 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