2009-10-06 6 views
0

J'ai écrit une fonction récursive. Pour une raison quelconque, il ne s'appellera tout simplement pas après avoir traversé pour la première fois. Il prend juste le prochain élément de la boucle sans descendre plus profond. J'utilise Visual Studio 10 et je manque de sommeil.Echec de recurse

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); 
    } 
} 

Répondre

8
this.GeneratePath(presentDepth); 

devrait être

foreach (var i in this.GeneratePath(presentDepth)) 
{ 
    yield return ... 
} 
Questions connexes