XName.Inequality(XName, XName) Operator

Definition

Returns a value indicating whether two instances of XName are not 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 not equal; otherwise false.

Examples

The following C# example compares an XName object to a string, which invokes this operator.

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

This example produces the following output:

False
False

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