Getting the previous sibling of a node using Roslyn
You could iterate over the ChildNodes only once with the Zip extension where the first collection starts at the first element and the other one at the second element with Skip(1). This will produce tuples with pairs such as Previous &amp; Current. Now you can filter it and pick at the same time the Last element that satisfies the condition:

var childNodes = new[] { "a", "a", "b", "c", "a" };

var previousSibling =
    childNodes
        .Zip(childNodes.Skip(1), (p, c) =&gt; (Previous: p, Current: c))
        .Last(t =&gt; t.Current == "c").Previous; // b