Rect.Inequality Operator (Rect, Rect)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.


Compares two rectangles for inequality.

Namespace:   System.Windows
Assembly:  WindowsBase (in WindowsBase.dll)

Public Shared Operator <> (
	rect1 As Rect,
	rect2 As Rect
) As Boolean


Type: System.Windows.Rect

The first rectangle to compare.

Type: System.Windows.Rect

The second rectangle to compare.

Return Value

Type: System.Boolean

true if the rectangles do not have the same Location and Size values; otherwise, false.

This operation tests for object inequality.

In this comparison, two instances of Double.NaN are considered equal.


A rectangle's position and dimensions are described by Double values. Because Double values can lose precision when operated upon, a comparison between two values that are logically equal might fail.

The following example shows how to use the Inequality operator to determine if two rectangles are not exactly equal.

Private Function overloadedInequalityOperatorExample() As Boolean
	' Initialize new rectangle.
	Dim myRectangle As New Rect()

	' The Location property specifies the coordinates of the upper left-hand 
	' corner of the rectangle. 
	myRectangle.Location = New Point(10, 5)

	' Set the Size property of the rectangle with a width of 200
	' and a height of 50.
	myRectangle.Size = New Size(200, 50)

	' Create second rectangle to compare to the first.
	Dim myRectangle2 As New Rect()
	myRectangle2.Location = New Point(0, 0)
	myRectangle2.Size = New Size(200, 50)

	' Check if the two Rects are not equal using the overloaded inequality operator.
	' notEqual is true because although the size of each rectangle is the same,
	' the locations are different.
	Dim notEqual As Boolean = (myRectangle <> myRectangle2)

	' Returns true.
	Return notEqual

End Function

.NET Framework
Available since 3.0
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Return to top