Rect.Inequality(Rect, Rect) 運算子
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
比較兩個矩形是否不相等。
public:
static bool operator !=(System::Windows::Rect rect1, System::Windows::Rect rect2);
public static bool operator != (System.Windows.Rect rect1, System.Windows.Rect rect2);
static member op_Inequality : System.Windows.Rect * System.Windows.Rect -> bool
Public Shared Operator != (rect1 As Rect, rect2 As Rect) As Boolean
參數
- rect1
- Rect
要比較的第一個矩形。
- rect2
- Rect
要比較的第二個矩形。
傳回
如果矩形沒有相同的 Location 和 Size 值則為 true
,否則為 false
。
範例
下列範例示範如何使用 Inequality 運算子來判斷兩個矩形是否不完全相等。
private Boolean overloadedInequalityOperatorExample()
{
// Initialize new rectangle.
Rect myRectangle = 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.
Rect myRectangle2 = 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.
bool notEqual = (myRectangle != myRectangle2);
// Returns true.
return notEqual;
}
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
備註
此作業會測試物件不相等。
在此比較中,會將 的 Double.NaN 兩個實例視為相等。
這個運算子的對等方法為 Rect.Equals(Rect, Rect)