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);
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.

適用於

另請參閱