<p>I would deal with this by making a small change to my design (assuming the snippet in your question is pseudocode for a class):</p>
public void Delete()
<p>This makes a little bit more work for you maintaining an extra reference when manipulating your object graph, but saves you a lot of effort and code when doing things like deletes as you can see above.</p>
<p>You haven't shown how you're constructing <code>TreeNode</code>s, but I'd make the parent and a collection for the children arguments of the constructor.</p>
<p>This tip was originally posted on <a href="http://stackoverflow.com/questions/30689905/Delete%20item%20in%20nested%20collections%20of%20Nth%20level/30690054">Stack Overflow</a>.</p>
Get New Tutorials Delivered to Your Inbox
New tutorials will be sent to your Inbox once a week.