Iterator blocks and inheritance

前端 未结 4 1869
無奈伤痛
無奈伤痛 2021-02-13 01:47

Given a base class with the following interface:

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


        
4条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-13 02:18

    How about:

    public class Derived : Base
    {
        public override IEnumerable GetListOfStuff()
        {
            return base.GetListOfStuff().Concat(GetMoreStuff());        
        }
        private IEnumerable GetMoreStuff()
        {
            yield return "Fourth";
            yield return "Fifth";
        }
    }
    

提交回复
热议问题