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

  • Home
  • SEARCH
  • 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 891679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T13:55:40+00:00 2026-05-15T13:55:40+00:00

I have two classes, GenericList and SpecificList , where SpecificList inherits from GenericList .

  • 0

I have two classes, GenericList and SpecificList, where SpecificList inherits from GenericList. GenericList implements IEnumerable<GenericItem> and SpecificList implements IEnumerable<SpecificItem>. SpecificItem inherits from GenericItem. I have to implement GetEnumerator in both GenericList and SpecificList since they implement IEnumerable<T>. In GenericList, it’s easy enough, I just return the enumerator for the underlying List<T>:

public IEnumerator<GenericItem> GetEnumerator()
{
    return genericItemsList.GetEnumerator();
}

However, in SpecificList, it seems trickier. It seems risky to cast IEnumerator<GenericItem> to IEnumerator<SpecificItem>, and I don’t know if that would even work. Instead, I did the following:

public new IEnumerator<SpecificItem> GetEnumerator()
{
    IEnumerator<GenericItem> enumerator = base.GetEnumerator();
    while (enumerator.MoveNext())
    {
        yield return (SpecificItem)enumerator.Current;
    }
}

This compiles fine and a simple MSTest unit test calling SpecificList.GetEnumerator() seems to show it works. However, ReSharper highlights base in the above method with the following warning:

Access to GenericList.GetEnumerator through ‘base’ keyword from anonymous method, lambda expression, query expression or iterator results in unverifiable code

Is this something I should worry about? Should I do something differently?

Edit: I’m using ReSharper 5.1 Full Edition Pre-Release Build 5.1.1715.35.

Also, I should take a break from running MSTest unit tests: I just hit Ctrl+R, Ctrl+T in Chrome to reload the page…

  • 1 1 Answer
  • 2 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-15T13:55:41+00:00Added an answer on May 15, 2026 at 1:55 pm

    R# is correct that accessing the base keyword inside an iterator / lambda in the 3.0 version of the C# compiler could result in unverifiable code. When it does or doesn’t is a bit complex and I won’t attempt to cover it here.

    The easiest way to work around this is to wrap the call to base.GetEnumerator in another non-static private method and reference that from your iterator.

    private IEnumerator<GenericItem> GetBaseEnumerator() {
      return base.GetEnumerator();
    }
    
    public new IEnumerator<SpecificItem> GetEnumerator()
    {
        IEnumerator<GenericItem> enumerator = GetBaseEnumerator();
        while (enumerator.MoveNext())
        {
            yield return (SpecificItem)enumerator.Current;
        }
    }
    

    I’m fairly certain this bug was fixed in the 4.0 version of the C# compiler.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 490k
  • Answers 490k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Not a complete answer to the question, but just to… May 16, 2026 at 9:52 am
  • Editorial Team
    Editorial Team added an answer I think it depends on whether you want to capture… May 16, 2026 at 9:52 am
  • Editorial Team
    Editorial Team added an answer Ok having used the jquery irc channel i managed to… May 16, 2026 at 9:52 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

If I have these two classes: class A {} class B : A {}
I have implemented inheritance for two parent classes called Table and Field . Each
I have two classes, and want to include a static instance of one class
I have two classes, Foo and Bar, that have constructors like this: class Foo
I have two classes. One is a management class, which stores a bunch of
I have a simple question (working with Java). I have two classes, one represents
I'm having trouble trying to implement a shared method/property between two classes created by
Let's say I have the following two classes: public class Person { public string
Two part question: Do browsers have a built-in CSS interpreter like they do for
Scenario: I have a generic list of Audits and a generic list of AuditImages.

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.