语言

XName.Implicit(String to XName) 操作员

定义

重要

此 API 不符合 CLS。

将格式化为扩展的 XML 名称(即){namespace}localname的字符串转换为对象 XName 。

public:
 static operator System::Xml::Linq::XName ^(System::String ^ expandedName);
[System.CLSCompliant(false)]
public static implicit operator System.Xml.Linq.XName(string expandedName);
[System.CLSCompliant(false)]
public static implicit operator System.Xml.Linq.XName?(string? expandedName);
[<System.CLSCompliant(false)>]
static member op_Implicit : string -> System.Xml.Linq.XName
Public Shared Widening Operator CType (expandedName As String) As XName

参数

expandedName
String

一个字符串,包含格式 {namespace}localname的扩展 XML 名称。

返回

XName从扩展名称构造的对象。

特性

示例

以下示例通过向其分配一个字符串来创建一个 XName ,该字符串调用此隐式转换运算符。

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);
Imports <xmlns="http://www.adventure-works.com">

Module Module1
    Sub Main()
        Dim el As XElement = New XElement("{http://www.adventure-works.com}Root", "content")
        Console.WriteLine(el)

        ' The preferred approach is to import a global namespace and
        ' use an XML literal.
        Dim root As XElement = <Root>content</Root>
        Console.WriteLine(root)
    End Sub
End Module

此示例生成以下输出:

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

注解

创建字符串或XElement将字符串传递给相应的构造函数时XAttribute,将使用此隐式运算符。

适用于

另请参阅