Export (0) Print
Expand All

XNamespace.Addition Operator

Combines an XNamespace object with a local name to create an XName.

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

public static XName operator +(
	XNamespace ns,
	string localName
)

Parameters

ns
Type: System.Xml.Linq.XNamespace
An XNamespace that contains the namespace.
localName
Type: System.String
A String that contains the local name.

Return Value

Type: System.Xml.Linq.XName
The new XName constructed from the namespace and local name.

This operator enables the common idiom of combining a namespace and a local name in the construction of an element or attribute. This idiom provides some of the benefits of having namespace prefixes, in that you can refer to a namespace using a variable that is short. This eliminates syntactic noise in the code that creates XML trees.

The following example shows the use of the + operator to create an XName from an XNamespace and a local name.


StringBuilder output = new StringBuilder();
XNamespace aw = "http://www.adventure-works.com";
XElement root = new XElement(aw + "Root",
    new XElement(aw + "Child")
);
output.Append(root + Environment.NewLine);

OutputTextBlock.Text = output.ToString();


Silverlight

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

ADD
Show:
© 2015 Microsoft