Iterator blocks and inheritance.
Posted
by Dave Van den Eynde
on Stack Overflow
See other posts from Stack Overflow
or by Dave Van den Eynde
Published on 2010-03-12T13:01:14Z
Indexed on
2010/03/12
13:07 UTC
Read the original article
Hit count: 244
Given a base class with the following interface:
public class Base
{
public virtual IEnumerable<string> GetListOfStuff()
{
yield return "First";
yield return "Second";
yield return "Third";
}
}
I want to make a derived class that overrides the method, and adds its own stuff, like so:
public class Derived : Base
{
public override IEnumerable<string> GetListOfStuff()
{
foreach (string s in base.GetListOfStuff())
{
yield return s;
}
yield return "Fourth";
yield return "Fifth";
}
}
However, I'm greeted with a warning that "access to a member through a base keyword from an iterator cannot be verified".
What's the accepted solution to this problem then?
© Stack Overflow or respective owner