Iterator blocks and inheritance

前端 未结 4 1995
心在旅途
心在旅途 2021-02-13 01:58

Given a base class with the following interface:

public class Base
{
    public virtual IEnumerable GetListOfStuff()
    {
        yield return \"F         


        
4条回答
  •  独厮守ぢ
    2021-02-13 02:33

    It's because the iterator gets turned into a private class, and accessing superclass methods from an inner class is not verifiable (as it has to force the 'this' pointer to something other than itself).

    Try creating a new private method in Derived:

    private IEnumerable GetBaseListOfStuff()
    {        
        return base.GetListOfStuff();
    }
    

    and call that instead of base.GetListOfStuff()

提交回复
热议问题