Edit

Share via


XName.Equality(XName, XName) Operator

Definition

Returns a value indicating whether two instances of XName are equal.

C#
public static bool operator ==(System.Xml.Linq.XName left, System.Xml.Linq.XName right);
C#
public static bool operator ==(System.Xml.Linq.XName? left, System.Xml.Linq.XName? right);

Parameters

left
XName

The first XName to compare.

right
XName

The second XName to compare.

Returns

true if left and right are equal; otherwise false.

Examples

The following example shows some comparisons between XName objects and strings.

C#
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");

This example produces the following output:

True
True
True

Remarks

The operator overloads == and != are included to enable comparisons between XName and a string, such aselement.Name == "SomeElementName". The predefined reference equality operators in C# require one operand to be convertible to the type of the other through reference conversions only. These operators do not consider the implicit conversion from string to XName.

Applies to

Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

See also