IndexOf

NodeCollection.IndexOf method

Returns the zero-based index of the specified node.

public int IndexOf(Node node)
ParameterTypeDescription
nodeNodeThe node to locate.

Return Value

The zero-based index of the node within the collection, if found; otherwise, -1.

Remarks

This method performs a linear search; therefore, the average execution time is proportional to Count.

Examples

Shows how to get the index of a node in a collection.

Document doc = new Document(MyDir + "Tables.docx");

Table table = doc.FirstSection.Body.Tables[0];
NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true);

Assert.That(allTables.IndexOf(table), Is.EqualTo(0));

Row row = table.Rows[2];

Assert.That(table.IndexOf(row), Is.EqualTo(2));

Cell cell = row.LastCell;

Assert.That(row.IndexOf(cell), Is.EqualTo(4));

See Also