XName.Implicit(String to XName) 运算符 
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
重要
此 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.XNamePublic 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>  
注解
创建字符串或XAttribute将字符串传递给相应的构造函数时XElement,将使用此隐式运算符。