Check out example codes for "C# walk down a tree and back". It will help you in understanding the concepts better.

Code Example 1

public static IEnumerable<T> Traverse<T>(T item, Func<T, IEnumerable<T>> childSelector)
    var stack = new Stack<T>();
    while (stack.Any())
        var next = stack.Pop();
        yield return next;
        foreach (var child in childSelector(next))

Learn ReactJs, React Native from