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

範例

下列範例會顯示物件與字串之間的一些比較 XNameThe 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.

適用於

另請參閱