XName.Implicit(String to XName) 运算符
定义
重要
此 API 不符合 CLS。
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 名称。A string that contains an expanded XML name in the format {namespace}localname.
返回
从展开名称构造的 XName 对象。An XName object constructed from the expanded name.
- 属性
示例
下面的示例 XName 通过为其分配一个字符串来创建,该字符串调用此隐式转换运算符。The following example creates an XName by assigning a string to it, which invokes this implicit conversion operator.
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
该示例产生下面的输出:This example produces the following output:
<Root xmlns="http://www.adventure-works.com">content</Root>
<Root xmlns="http://www.adventure-works.com">content</Root>
注解
当创建 XElement 或 XAttribute 通过将字符串传递到适当的构造函数时,将使用此隐式运算符。You are using this implicit operator when you create an XElement or XAttribute by passing a string to the appropriate constructor.