XName.Equality(XName, XName) 运算符

定义

返回一个值,该值指示 XName 的两个实例是否相等。Returns a value indicating whether two instances of XName are equal.

public:
 static bool operator ==(System::Xml::Linq::XName ^ left, System::Xml::Linq::XName ^ right);
public static bool operator == (System.Xml.Linq.XName left, System.Xml.Linq.XName right);
public static bool operator == (System.Xml.Linq.XName? left, System.Xml.Linq.XName? right);
static member ( = ) : System.Xml.Linq.XName * System.Xml.Linq.XName -> bool
Public Shared Operator == (left As XName, right As XName) As Boolean

参数

left
XName

要比较的第一个 XNameThe first XName to compare.

right
XName

要比较的第二个 XNameThe second XName to compare.

返回

Boolean

如果 leftright 相等,则为 true;否则为 falsetrue if left and right are equal; otherwise false.

示例

下面的示例演示了 XName 对象和字符串之间的一些比较。The following example shows some comparisons between XName objects and strings.

XName xn;  
xn = XName.Get("Root");  
Console.WriteLine(xn == "Root");  

xn = XName.Get("Root", "http://www.adventure-works.com");  
Console.WriteLine(xn == "{http://www.adventure-works.com}Root");  

XElement root = new XElement("Root", "content");  
Console.WriteLine(root.Name == "Root");  
Dim xn As XName  
xn = XName.Get("Root")  
Console.WriteLine(xn = "Root")  

xn = XName.Get("Root", "http://www.adventure-works.com")  
Console.WriteLine(xn = "{http://www.adventure-works.com}Root")  

Dim root As XElement = New XElement("Root", "content")  
Console.WriteLine(root.Name = "Root")  

该示例产生下面的输出:This example produces the following output:

True  
True  
True  

注解

包含运算符重载 ==!= 以启用与之间的比较 XName string ,如 element.Name == "SomeElementName"The operator overloads == and != are included to enable comparisons between XName and a string, such aselement.Name == "SomeElementName". C # 中预定义的引用相等运算符要求一个操作数只能通过引用转换转换为另一个操作数。The predefined reference equality operators in C# require one operand to be convertible to the type of the other through reference conversions only. 这些运算符不考虑从字符串到的隐式转换 XNameThese operators do not consider the implicit conversion from string to XName.

适用于