public void NodeEnumerationHotRemove()
{
//ExStart
//ExFor:ParagraphCollection.ToArray
//ExSummary:Demonstrates how to use "hot remove" to remove a node during enumeration.
DocumentBuilder builder = new DocumentBuilder();
builder.Writeln("The first paragraph");
builder.Writeln("The second paragraph");
builder.Writeln("The third paragraph");
builder.Writeln("The fourth paragraph");
// Hot remove allows a node to be removed from a live collection and have the enumeration continue.
foreach (Paragraph para in builder.Document.FirstSection.Body.GetChildNodes(NodeType.Paragraph, true))
{
if (para.Range.Text.Contains("third"))
{
// Enumeration will continue even after this node is removed.
para.Remove();
}
}
//ExEnd
}