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>

備註

當您建立 XElementXAttribute 將字串傳遞至適當的建構函式時,會使用此隱含運算子。

適用於

另請參閱