📅  最后修改于: 2022-03-11 14:49:24.180000             🧑  作者: Mango
public static IEnumerable Traverse(T item, Func> childSelector)
{
var stack = new Stack();
stack.Push(item);
while (stack.Any())
{
var next = stack.Pop();
yield return next;
foreach (var child in childSelector(next))
stack.Push(child);
}
}