Iterator blocks and inheritance

前端 未结 4 1988
心在旅途
心在旅途 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:29

    How about:

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

提交回复
热议问题