Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4029160
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:18:37+00:00 2026-05-20T11:18:37+00:00

I have been delved in C++ world for a while, but now I’m in

  • 0

I have been delved in C++ world for a while, but now I’m in .NET world again, VB and C# and I wondered if you have a class that represents a collection of something, and you want the ability to use this in a foreach loop, etc… is it better to implement IEnumerable and IEnumerator yourself or should you inherit from the List<T> where T is the object type in it’s singular form?

I know in C++ for example, inheriting from a container is considered a bad idea.

But what about .NET.

EDIT:

It seems my question was slightly misunderstood. I am not unhappy at all with existing collections in .NET. Here is my problem, I have a class called ‘Person’ and I need a collection called ‘Scouts’, which I want in an Class called ‘Scouts’, at this point I’d like to be able to write

foreach Person in Scouts …

What is the best way to get this Scouts as a collection of People, and be able to use it in a foreach loop?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T11:18:38+00:00Added an answer on May 20, 2026 at 11:18 am

    You said:

    I have a class called ‘Person’ and I
    need a collection called ‘Scouts’,
    which I want in an Class called
    ‘Scouts’, at this point I’d like to be
    able to write

    foreach Person in Scouts ...

    If I understand you correctly, you want:

    class Scouts : IEnumerable<Person>
    {
        private List<Person> scouts;
    
        public IEnumerator<Person> GetEnumerator()
        {
            return scouts.GetEnumerator();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been programming for a while in objective-c, but I've unfortunately never delved very
Have been googling for a while, but I don't find any page which explains
Have been working in Ruby for a while, but usually in the context of
Have been trying to encrypt an xml file to a string so that I
Have been looking on some tutorials for drawing canvas using SurfaceView, but the only
Have been searching how to convert a dictionary to a string. But the results
I have been working with SQL Server as a Developer a while. One thing
have been trying couple of hours now to make my iphone app universal. The
Have been hearing all around ArrayList getting obsolete these days. But I do have
Have been searching the net for the past hours to find a solution to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.