Count Property
Collapse the table of content
Expand the table of content

XmlNodeList.Count Property

Gets the number of nodes in the XmlNodeList.

Namespace:  System.Xml
Assembly:  System.Xml (in System.Xml.dll)

public abstract int Count { get; }

Property Value

Type: System.Int32
The number of nodes in the XmlNodeList.

The following example creates a XmlDocument object and uses the GetElementsByTagName method and the resulting XmlNodeList to display all the book titles.

using System;
using System.IO;
using System.Xml;

public class Sample
  public static void Main()
     XmlDocument doc = new XmlDocument();

     // Get and display all the book titles.
     XmlElement root = doc.DocumentElement;
     XmlNodeList elemList = root.GetElementsByTagName("title");
     for (int i=0; i < elemList.Count; i++)


The example uses the file 2books.xml as input.

<!--sample XML fragment-->
  <book genre='novel' ISBN='10-861003-324'>
    <title>The Handmaid's Tale</title>
  <book genre='novel' ISBN='1-861001-57-5'>
    <title>Pride And Prejudice</title>

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

XNA Framework

Supported in: 3.0, 2.0, 1.0
© 2015 Microsoft