2009-10-06 3 views
0

Я написал рекурсивную функцию. По какой-то причине он просто не назовет себя после того, как он пропустит первый раз. Он просто берет следующий элемент из цикла, не спускаясь глубже. Я использую Visual Studio 10, и мне не хватает сна.Неисправность

public IEnumerable<string> GeneratePath(int depth) 
{ 
    int presentDepth = depth; 
    char currentPosition = this.workingPath[presentDepth]; 
    presentDepth++; 

    foreach (char nextPosition in this.moveTable.GetPossibleNextPositions(currentPosition)) 
    { 
     this.workingPath[presentDepth] = nextPosition; 

     if (presentDepth < (ChessPiece.targetDepth - 1)) 
     { 
      Console.WriteLine("At least this wasn't ignored:{0}", new string(this.workingPath)); 
      this.GeneratePath(presentDepth); 
     } 
     else 
      yield return new string(this.workingPath); 
    } 
} 

ответ

8
this.GeneratePath(presentDepth); 

должен быть

foreach (var i in this.GeneratePath(presentDepth)) 
{ 
    yield return ... 
} 
Смежные вопросы