Прочетете на английски Редактиране

Споделяне чрез


XName.Implicit(String to XName) Operator

Definition

Important

This API is not CLS-compliant.

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

C#
[System.CLSCompliant(false)]
public static implicit operator System.Xml.Linq.XName(string expandedName);
C#
[System.CLSCompliant(false)]
public static implicit operator System.Xml.Linq.XName?(string? expandedName);

Parameters

expandedName
String

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

Returns

An XName object constructed from the expanded name.

Attributes

Examples

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

C#
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>

Remarks

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

Applies to

Продукт Версии
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

See also