Export (0) Print
Expand All
1 out of 1 rated this helpful - Rate this topic

XName.Implicit Operator

Converts a string formatted as an expanded XML name (that is,{namespace}localname) to an XName object.

This API is not CLS-compliant. 

Namespace:  System.Xml.Linq
Assembly:  System.Xml.Linq (in System.Xml.Linq.dll)
public static implicit operator XName (
	string expandedName
)

Parameters

expandedName
Type: System.String

A string that contains an expanded XML name in the format {namespace}localname.

Return Value

Type: System.Xml.Linq.XName
An XName object constructed from the expanded name.

You are using this implicit operator when you create an XElement or XAttribute by passing a string to the appropriate constructor.

The following example creates an XName by assigning a string to it, which invokes this implicit conversion operator.

XElement el = new XElement("{http://www.adventure-works.com}Root", "content");
Console.WriteLine(el);

// The preferred approach is to initialize an XNamespace object
// and use the overload of the addition operator.
XNamespace aw = "http://www.adventure-works.com";
XElement root = new XElement(aw + "Root", "content");
Console.WriteLine(root);

This example produces the following output:

<Root xmlns="http://www.adventure-works.com">content</Root>
<Root xmlns="http://www.adventure-works.com">content</Root>

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5

.NET Compact Framework

Supported in: 3.5

XNA Framework

Supported in: 3.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.