Cannot step into a method returning IEnumerable?

前端 未结 4 756
没有蜡笔的小新
没有蜡笔的小新 2020-12-15 17:29

I have a method that returns an IEnumerable like this..

public virtual IEnumerable ToPages(){
  // foreach logic
  yield return pages;

  // more         


        
4条回答
  •  情歌与酒
    2020-12-15 18:10

    Your enumerable method will only execute once you actually try to access the members.

    This is called "Deferred Execution" (see http://blogs.msdn.com/b/charlie/archive/2007/12/09/deferred-execution.aspx)

    Try actually accessing the IEnumerable which is returned, or just call;

    var p = obj.ToPages().ToList();
    

提交回复
热议问题