語言

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

一個包含擴充 XML 名稱的字串,格式為 {namespace}localname。

傳回

一個 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 or XAttribute 時,透過將字串傳給適當的建構子,就是在使用這個隱含運算子。

適用於

另請參閱