Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
FirstNode Property
Collapse the table of content
Expand the table of content

XContainer.FirstNode Property

Get the first child node of this node.

Namespace:  System.Xml.Linq
Assemblies:   System.Xml.Linq (in System.Xml.Linq.dll)
  System.Xml.XDocument (in System.Xml.XDocument.dll)

public XNode FirstNode { get; }

Property Value

Type: System.Xml.Linq.XNode
An XNode containing the first child node of the XContainer.

The following example creates an element that contains child elements. It then gets the first child node of the parent element.

XElement xmlTree = new XElement("Root",
    new XElement("Child1", 1),
    new XElement("Child2", 2),
    new XElement("Child3", 3),
    new XElement("Child4", 4),
    new XElement("Child5", 5)
);
XNode firstNode = xmlTree.FirstNode;
Console.WriteLine(firstNode);

This example produces the following output:

<Child1>1</Child1>

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

XNA Framework

Supported in: 3.0

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone Silverlight 8.1, Windows Phone Silverlight 8

Portable Class Library

Supported in: Portable Class Library
Show:
© 2015 Microsoft