I don't like using an Instance variable to create a breadcrumb trail

The problem with using an instance variable to tag a way point as explored is that you might want to compute a second path simultaneously in a second thread of execution. In this instance the two threads of execution would interfere with each other leading to a miss computation of paths.
I solved this problem in a different way by creating a BreadCrumb structure.

private struct BreadCrumb
{
    public WayPoint Node;
    public WayPoint ExploredFrom;
}

and the using a Dictionary called Loaf to store the bread crumbs using the way point itself as the key.

    Dictionary<WayPoint, BreadCrumb> Loaf;

I can also use the dictionary object to determine whether a point has already been examined by using the .ContainsKey method.

Once the end point has been found I can unwind the trail to a List of WayPoints which I then return from my path finding function.

Okay I have discovered the hard way it is not a good idea to use objects as keys in C#.
I was storing an array neighbouring way points in an array against each way point so that each way point was aware of it’s immediate neighbours. I discovered that after I ran my own breadth first search code through the way points that some of the way points some how some of the referenced way points in the array magically became set to null despite them being read and not set. The path finding algorithm worked on the first pass but then failed to work on subsequent passes despite the fact that my code did not change any of the underlying data when transversing the way point network.
I did an experiment where I replaced the neighbour array with an array of neighbour names rather than references to actual way points and now my code worked, but I now have to look up the object reference from an array which is inefficient. I use object references all the time when I am coding in object pascal, but I am quickly discovering that object references can’t be trusted in C#.
I also wrote my own shortest path algorithm using a recursive method in the constructor to discover each branch in turn. However it turned out in C# the this variable isn’t set in the constructor so you can’t pass it to a child object. I find being able to pass a reference to a parent in constructors again in object pascal is extremely helpful as your child objects in a compound object are aware of the parent object and can reference the parent object if necessary.

Privacy & Terms