title: C# - How can i get the count of child elements using LINQ to XML
body: <p>This is an extract of the XML i'm using</p>
  
  <pre><code>    &lt;AccountNumber&gt;
        &lt;RecordID&gt;A9&lt;/RecordID&gt;
        &lt;SegmentLength&gt;14&lt;/SegmentLength&gt;
        &lt;Number&gt;6770307103&lt;/Number&gt;
      &lt;/AccountNumber&gt;
      &lt;PaymentCounter&gt;
        &lt;RecordID&gt;B2&lt;/RecordID&gt;
        &lt;SegmentLength&gt;14&lt;/SegmentLength&gt;
        &lt;History&gt;99&lt;/History&gt;
        &lt;Delinq30Day&gt;00&lt;/Delinq30Day&gt;
        &lt;Delinq60Day&gt;00&lt;/Delinq60Day&gt;
        &lt;Delinq90PlusDay&gt;00&lt;/Delinq90PlusDay&gt;
        &lt;DerogCnt&gt;00&lt;/DerogCnt&gt;
      &lt;/PaymentCounter&gt;
  </code></pre>
  
  <p>Here I'm trying to identify the number of child elements under AccountNumber and PaymentCounter. </p>
  
  <p>I'm looking for this answer
  AccountNumber count = 3
  PaymentCounter count = 7</p>
  
  <p>After I get the count, I will use the data to dynamically populate a table. </p>
  
  <p>I tried this : 
  int count1 = xmlDocument.Descendants("AccountNumber").Count();</p>
  
  <p>The count() in LINQ to XML will give me the number of times element "AccountNumber" is repeated in the XML, but doesnot give me the number of child elements. </p>
  
  <p>Is there a way to do this? </p>