Hello everyone I have a small problem and I feel a little bit stuck. I manage to get the object that I want, but I don't know how to return the path to that object (how I found it). My code looks like this at the moment:
P.S what I mean by path: every single item has it's name and id. I manage to find an object with id (which I give when call for recursion) and when I find it, I need to create string and add all of it's parents names to it and return it.
protected void FindPath(int depth, int id, InventLocationViewModel currentLocation)
{
if (depth < 0)
return;
if (currentLocation.Id == id)
{
selectedLocation = currentLocation;
return;
}
foreach (var child in currentLocation.ChildInventLocations)
{
FindPath(depth - 1, id, child);
}
}
protected void SelectedLocation(RecursiveSelectObject args)
{
currentLocation = locations.InventLocations.FirstOrDefault(e => e.Id == locationId.Value);
FindPath(args.Level, args.Id, currentLocation);
if (selectedLocation.Id == args.Id)
{
}
}
question from:
https://stackoverflow.com/questions/65906631/finding-a-path-of-recursion 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…