AddFirst Method (Object)
Collapse the table of content
Expand the table of content

XContainer.AddFirst Method (Object)

Adds the specified content as the first children of this document or element.

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

Public Sub AddFirst ( _
	content As Object _


Type: System.Object
A content object containing simple content or a collection of content objects to be added.

This method adds the new content before the existing content of the XContainer.

For details about the valid content that can be passed to this function, see Valid Content of XElement and XDocument Objects.

This method will raise the Changed and the Changing events.

The following example creates two XML trees, uses this method to add an XElement object as the first element to one of them. It also adds the results of a LINQ query to the XML tree.

Dim output As New StringBuilder
Dim srcTree As XElement = _

Dim xmlTree As XElement = _

xmlTree.AddFirst(New XElement("NewChild", "new content"))
xmlTree.AddFirst( _
    From el In srcTree.Elements() _
    Where CInt(el) > 3 _
    Select el _
' Even though Child9 does not exist in srcTree, the following statement will not
' throw an exception, and nothing will be added to xmlTree

OutputTextBlock.Text = output.ToString()


Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Community Additions

© 2015 Microsoft