Get First Descendants in CSharp
Description
The following code shows how to get First Descendants.
Example
/* w ww . j a va2 s . c om*/
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Linq;
using System.Reflection;
using System.Xml.Linq;
class Program {
static void Main(string[] args) {
string doc = @"<people>
<person>
<id>1</id>
<firstname>C</firstname>
<lastname>L</lastname>
<idrole>1</idrole>
</person>
</people>";
XElement xml = XElement.Parse(doc);
XElement firstName = xml.Descendants("person").First();
Console.WriteLine(firstName.IsEmpty);
}
}