A
Alberto Poblacion
AAaron123 said:[...]Alberto Poblacion" (myself) said:string shortestPath = "";
[...]
if (s.Length<shortestPath.Length)
shortestPath = s; //this copies a reference
When you enter the loop shortestPath.Length equals zero, doesn't it?
You will never find a lower value in s.Length.
Ooops! Sorry!. This is what happens when I type a piece of code out of
memory without testing it, and I concentrate on a different aspect of the
code (the fact that it was copying references instead of copying the
strings).
A couple of solutions have already been proposed in other messages:
Either use an int to represent the length and preload it with int.MaxValue,
or preload the shortestPath with an existing path from the array.