XName.Inequality(XName, XName) 运算符

定义

返回一个值,该值指示 XName 的两个实例是否相等。Returns a value indicating whether two instances of XName are not 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 op_Inequality : 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 not equal; otherwise false.

示例

下面的 c # 示例将一个 XName 对象与一个用于调用此运算符的字符串进行比较。The following C# example compares an XName object to a string, which invokes this operator.

XNamespace aw = "http://www.adventure-works.com";  
XElement root = new XElement(aw + "Root", "content");  

Console.WriteLine(root.Name != "{http://www.adventure-works.com}Root");  

// the following is the preferred idiom  
Console.WriteLine(root.Name != aw + "Root");  
Imports <xmlns="http://www.adventure-works.com">  

Module Module1  
    Sub Main()  
        Dim root As XElement = <Root>content</Root>  
        Console.WriteLine(root.Name <> "{http://www.adventure-works.com}Root")  

        ' the following is the preferred idiom  
        Console.WriteLine(root.Name <> GetXmlNamespace() + "Root")  
    End Sub  
End Module  

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

False  
False  

注解

包含运算符重载 ==!= 以启用与字符串之间的比较 XName ,如 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.

适用于