IndexOf

NodeCollection.IndexOf method

يعيد الفهرس المبني على الصفر للعقدة المحددة.

public int IndexOf(Node node)
معامليكتبوصف
nodeNodeالعقدة التي يجب تحديد موقعها.

قيمة الإرجاع

الفهرس المبني على الصفر للعقدة داخل المجموعة، إذا تم العثور عليه؛ وإلا، -1.

ملاحظات

تقوم هذه الطريقة بإجراء بحث خطي؛ وبالتالي فإن متوسط وقت التنفيذ يتناسب معCount.

أمثلة

يوضح كيفية الحصول على فهرس العقدة في المجموعة.

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

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

Assert.AreEqual(0, allTables.IndexOf(table));

Row row = table.Rows[2];

Assert.AreEqual(2, table.IndexOf(row));

Cell cell = row.LastCell;

Assert.AreEqual(4, row.IndexOf(cell));

أنظر أيضا