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 8696781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:21:04+00:00 2026-06-13T01:21:04+00:00

I am learning about implementing interfaces and generics, I made this code, but VStudio

  • 0

I am learning about implementing interfaces and generics, I made this code, but VStudio says that I did not implement System.Collections.Enumerable.GetEnumerator().
Did I not do this below, generically? It wants two implementations?

namespace Generic_cars
{
 class VehicleLot:IEnumerable<Vehicle>
 {
    public List<Vehicle> Lot = new List<Vehicle>();

    IEnumerator<Vehicle> IEnumerable<Vehicle>.GetEnumerator()
    {
        foreach (Vehicle v in Lot) { yield return v; };
    }
 }
}
  • 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-06-13T01:21:06+00:00Added an answer on June 13, 2026 at 1:21 am

    You are implementing IEnumerable<Vehicle>, a generic interface that is strongly typed to hold Vehicle objects. That interface, however, derives from the older IEnumerable interace that is not generic, and is typed to hold object objects.

    If you want to implement the generic version (which you do) you need to also implement the non-generic version. Typically you would implement the non-generic GetEnumerator by simply calling the generic version.

    Also, you probably don’t want to be explicitly implementing GetEnumerator<Vehicle> the way you are; that will require you to explicitly cast your objects to IEnumerable<Vehicle> in order to use them. Instead, you probably want to do this:

    public IEnumerator<Vehicle> GetEnumerator() {
        foreach( Vehicle item in items ) {
            yield return item;
        }
    }
    
    IEnumerator IEnumerable.GetEnumerator() {
        return GetEnumerator();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm not a math guy in the least but I'm interested in learning about
i'm a newbie in dropbox development in IOS, i'm still learning about implementing dropbox
Learning about notifyAll made me question something about notify: in a typical situation we
I am learning about raw sockets. I heard that ping utility is using raw
For my Java class, we are learning about interfaces, polymorphism, inheritance, etc. The homework
Hello everyone I'm currently implementing a simple programming language for learning experience but I'm
I'm learning the use of boost smart pointers but I'm a bit confused about
I'm just learning about SproutCore now, seems great. But I can't find a good
In learning about Web Deploy I came across some netsh.exe commands that talk about
Just learning about mercurial's --style and --template options that can be used on hg

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.